Skip to content

Environment

Python 3 installation & Setup Guide

  1. macOS
  2. Windows
  3. Linux
    • Use package managers, ask the teacher for a step by step guide.

Find your favourite code editor

  1. Visual Studio Code (Recommended)

    Download Visual Studio Code * MacOS:https://go.microsoft.com/fwlink/?LinkID=620882 * Windows:https://aka.ms/win32-x64-user-stable

  2. Vim & Emacs

  3. Others

    • Notepad++
  4. Find a shell

  5. Command Prompt(Windows)

    Use the shortcuts "Win+R", and input "cmd" to open Command Prompt app.
    
    ![图片](https://uploader.shimo.im/f/uvNjCbqeAEOnIeZ2.png!thumbnail)
    
  6. Terminal App(MacOS)

    Use the shortcuts "Command + Space" to open spotlight search, and input "terminal" to open Terminal App.
    
    ![图片](https://uploader.shimo.im/f/kIPLaZ3Iyn7TL99p.png!thumbnail)
    
  7. 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.
    
    ![图片](https://uploader.shimo.im/f/4HVyarCcP7iBf7pO.png!thumbnail)
    
    ![图片](https://uploader.shimo.im/f/2M3rS4xh2vqgVnAz.png!thumbnail)
    
  8. Tasks

  9. 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
  10. 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:

    print("Hello, Theia Academy!")
    
    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:

    python hello.py
    
  11. 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)
            ])
         )
    
  12. 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)