By the end of this course, students will have a fundamental understanding of Python programming, including variables, basic data types, loops, and functions. They will use Python to create simple programs, applying logical thinking and problem-solving skills.
Objective: Familiarize students with Python, its uses, and how to set up a basic programming environment.
Activities:
print("Hello, World!")
Homework: Write Python code to print their name, favorite color, and age.
Objective: Understand how to use variables and basic data types (strings, integers, and floats).
Activities:
name = input("What is your name? ") age = input("How old are you? ") print("Hello " name "! You are " age " years old.")
Homework: Create a simple program that asks for the user’s name and favorite number, then prints a message including both.
Objective: Learn how to perform basic mathematical operations and introduce conditionals (if-else).
Activities:
num1 = int(input("Enter first number: ")) num2 = int(input("Enter second number: ")) if num1 > num2: print(str(num1) " is greater than " str(num2)) else: print(str(num2) " is greater than " str(num1))
Homework: Create a number guessing game where the program randomly selects a number, and the student must guess whether it is higher or lower.
Objective: Understand how to use loops to repeat actions in a program.
Activities:
for i in range(1, 11): print(i) num = 1 while numHomework: Write a program that asks the user for a number and prints the multiplication table for that number using a loop.
Lesson 5: Functions and Modular Programming
Objective: Learn how to create and use functions to organize code.
Activities:
def calculate_area(length, width): return length * width length = int(input("Enter length: ")) width = int(input("Enter width: ")) print("Area of the rectangle is:", calculate_area(length, width))
Homework: Write a program that includes a function to calculate and return the perimeter of a rectangle.
Objective: Apply all the learned concepts to build a simple interactive game.
Activities:
import random def guessing_game(): secret_number = random.randint(1, 20) guess = None attempts = 0 while guess != secret_number: guess = int(input("Guess the number (1-20): ")) attempts = 1 if guess secret_number: print("Too high!") else: print("You guessed it in " str(attempts) " tries!") guessing_game()
Homework: Finish the project, test it, and add at least one new feature (e.g., allowing the user to set the range of numbers).
This course provides a fun and hands-on introduction to Python programming, helping students develop logical thinking and problem-solving skills through coding. By the end of the course, students will have created their own simple game and have a strong foundation for further learning in Python.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3