Kirubel Teka Part6 Fill Table
Kirubel Teka Part6 Fill Table
Kirubel Teka Part6 Fill Table
Part 1: Printing
Comments are very important in your programs. They are used to tell you what
something does in English, and they also are used to disable parts of your program if you
need to remove them temporarily. Here’s how you use comments in Python:
Part 3: Variables
1 cars = 100
2 space_in_a_car = 4.0
3 drivers = 30
4 passengers = 90
5 cars_not_driven = cars - drivers
6 cars_driven = drivers
7 carpool_capacity = cars_driven * space_in_a_car
8 average_passengers_per_car = passengers / cars_driven
9
10 type(cars) # Try the other variables
11 print( "There are", cars, "cars available." )
12 print( "There are only", drivers, "drivers available." )
13 print( "There will be", cars_not_driven, "empty cars today." )
14 print( "We can transport", carpool_capacity, "people today." )
15 print( "We have", passengers, "to carpool today." )
Part 4: User Input
1 name = input()
2 # Enter Name
3 print(name)
4 print(‘Hello ’, name)
5 # What problem do you see?
6 name = input(‘Enter your name: ’)
7 print(‘Hi ’, name)
Part 5: Debugging
Part 6: Casting
1 print(5 < 3)
2 5 > 3
3 True and False
4 Type(5 < 3)
5 ‘hi’ > ‘hello’
6 5 = 5
7 #What went wrong?
8 favorite_color = ‘blue’
9 user_favorite = input(‘Enter your favorite color: ’)
10 favorite_color == user_favorite
True True
False False
True True
False False
Exercise
1. Evaluate an expression from user
Accept an algebraic expression from user and print out the result of the expression
2.
3.
secret_num = 10
temp = secret_num + 8 #evaluate secret + 8, and put the result
#in temp
temp = temp * 2 #evaluate temp * 2, and put the results
#in temp
temp = temp / 4
answer = temp - secret_num / 2
print(answer)