Environment
Python 3 installation & Setup Guide¶
- macOS
- Download URL:https://www.python.org/ftp/python/3.8.5/python-3.8.5-macosx10.9.pkg
- Double click the pkg file to install.
- Windows
- Download URL:https://www.python.org/ftp/python/3.8.3/python-3.8.3-amd64.exe
- Double click the executable file to install, then Next, Next, Next....
- Linux
- Use package managers, ask the teacher for a step by step guide.
Find your favourite code editor¶
-
Visual Studio Code (Recommended)
Download Visual Studio Code * MacOS:https://go.microsoft.com/fwlink/?LinkID=620882 * Windows:https://aka.ms/win32-x64-user-stable
-
Vim & Emacs
-
Others
- Notepad++
-
Find a shell
-
Command Prompt(Windows)
Use the shortcuts "Win+R", and input "cmd" to open Command Prompt app. 
-
Terminal App(MacOS)
Use the shortcuts "Command + Space" to open spotlight search, and input "terminal" to open Terminal App. 
-
Visual Studio Code(Recommended)
In Visual Studio Code app, Choose "Terminal" > "New Terminal" , then you will get a terminal window at the bottom of the main window.  
-
Tasks
-
Use an interactive shell to run python scripts.
Run the command "python" at the Terminal App(MacOS) , Command Prompt(Windows) or Terminal Window at the Visual Studio Code, and you will get an python interfactive shell.
The first line of this example is the command that starts the Python interpreter at a command prompt. The next three lines are messages from the interpreter.If your python version is not 3.X.X, use the command "python3" instead of "python". The fourth line starts with >>>, which is thePython prompt. The interpreter uses the prompt to indicate that it is ready for instructions.
Now, you could try to calculate some simple math expressions, and see what these expressions will output.
- 1234567895 * 987654321
12.423 * (1+ 5/7 - 4)
2**100
2**0.5
3 == 4
3 != 4
3 == (1+2)
17 / 4
17 // 4
17 % 4
-
Say hello to Theia Academy by using Python.
You can write a program in a file and use the interpreter to execute the contents of the file. Such a file is called a script. For example, we used our recommended text editor "Visual Studio Code" to create a file named hello.py with the following contents:
By convention, files that contain Python programs have names that end with .py. To execute the program, we have to tell the interpreter the name of the script. you can type the command below to run the python script:print("Hello, Theia Academy!")
python hello.py
-
Draw a heart.
We could use the script below to draw a heart using python.
print( '\n'.join ([ ''.join ([ ( 'Love'[(x-y) % len('Love')] if ((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3 <= 0 else ' ' ) for x in range(-30, 30) ]) for y in range(30, -30, -1) ]) )
-
Play number guessing game.
Run the scripts below to play guessing name.
# Number Guessing Game implementation # using Python import random print("Number guessing game") # randint function to generate the # random number b/w 1 to 9 number = random.randint(1, 9) # number of chances to be given # to the user to guess the number # or it is the inputs given by user # into input box here number of # chances are 5 chances = 0 print("Guess a number (between 1 and 9):") # While loop to count the number # of chances while chances < 5: # Enter a number between 1 to 9 guess = int(input()) # Compare the user entered number # with the number to be guessed if guess == number: # if number entered by user # is same as the generated # number by randint function then # break from loop using loop # control statement "break" print("Congratulation YOU WON!!!") break # Check if the user entered # number is smaller than # the generated number elif guess < number: print("Your guess was too low: Guess a number higher than", guess) # The user entered number is # greater than the generated # number else: print("Your guess was too high: Guess a number lower than", guess) # Increase the value of chance by 1 chances += 1 # Check whether the user # guessed the correct number if chances == 5: print("YOU LOSE!!! The number is", number)