🐍

Getting Started with Python Programming

Jul 24, 2024

Introduction to Programming with Python

Overview

  • Presenter: Gary Sims
  • Topic: Learning to program using Python

Downloading Python on Windows

  1. Go to python.org
  2. Click on "Downloads" in the menu bar
  3. Choose between:
    • Python 3.6.5 (recommended)
    • Python 2.7.14 (older version, for legacy systems)
  4. Download the .exe file
  5. Run the installer to install Python

Setting Up Python IDLE

  • Look for the IDLE program after installation:
    • Either on the desktop or in the Start Menu
  • Launch IDLE, which will present the shell (three chevron prompts)

Writing a Simple Program

Creating a Guessing Game

  1. Go to File > New File to open the editor
  2. Start writing the Python program

Sample Code

  • Print statement: print("I am thinking of a number between 1 and 10")
  • Save as guess.py in preferred source code directory

Importing Libraries

  • Import random number functionality: import random

Setting up the Game Logic

  1. Generate a random number: n = random.randint(1, 10)
  2. Initialize game run status: running = True
  3. Create a while loop to control game running: while running:
  4. Get user input and provide feedback:
    • Prompt user to make a guess: guess_string = input("Take a guess: ") guess = int(guess_string)
    • Compare guessed number with generated number: if guess == n: print("Well done, that is right!") running = False elif guess < n: print("Try a bigger number.") else: print("Try a smaller number.")
  5. Ensure proper indentation for Python to recognize code blocks

Running the Program

  • Save changes and run by selecting Run > Run Module
  • Example Gameplay:
    • User guesses – program provides hints until the correct number is guessed

Conclusion

  • The program lacks error checking (e.g., handling non-integer inputs)
  • Encouragement to explore Python further
  • Source code will be available in the video description

Call to Action

  • Feedback: Comments on further interest in deeper programming topics
  • Engage: Thumbs-up the video and subscribe for notifications