print("Hello, my name is NAME!")
Change "NAME" to your actual name and run it
Python can do math instantly. Try these:
5 + 3
10 - 4
6 * 7
20 / 4
2 ** 3
17 % 5
Challenge question: What do you think ** does? What about %?
**
%
Test your guess by trying different numbers
Instead of just calculating, we can save results:
my_age = 16 print(my_age)
favorite_number = 42 print(favorite_number)
Your turn: Create a variable with your actual age and print it
score = 10 print(score) score = 25 print(score)
What happened? The variable score changed from 10 to 25
score
Try it: Create a variable called points and change it several times
points
length = 5 width = 3 area = length * width print(area)
Code-along: Everyone type this rectangle area calculator
Next challenge: Make variables for your height and a friend's height, then find the difference
name = input("What's your name? ") print("Nice to meet you,", name)
Interactive time: Everyone run this and type your name when it asks
What's cool: The program waits for YOU to type something!
age = input("How old are you? ") print("Wow, you are", age, "years old!")
Try it now: Run this code and enter your age
Let's combine everything into one program:
print("Welcome to my first Python program!") name = input("What's your name? ") age = input("How old are you? ") print("Hello", name, "you are", age, "years old") print("Thanks for trying Python!")
Now modify the program above to:
5 minutes: Work on your personalized version
num1 = input("Enter first number: ") num2 = input("Enter second number: ") result = int(num1) + int(num2) print("The sum is:", result)
Don't worry about int() yet - we'll learn that soon!
int()
Spend the last few minutes trying to write a program that: