The first while-loop example
for i in range(0,10):
print(i)
Going backwards
Times table example
for i in range(1,10):
print("{0} x {1} = {2}".format(i, 5, 5*i))
Friend of 10 table
for i in range(0,11):
print("{0:>2} + {1:>2} = {2:>2}".format(i, 10 - i, 10))
Questions
What is the output of the following codes?
Display equations
Enter start number: 4
Enter end number: 7
Equations:
4 + 4 = 8
5 + 5 = 10
6 + 6 = 12
7 + 7 = 14
# ask user for start number
# ask user for end number
# display equations between the two input numbers
while loop that runs forever
while True:
user_input = input("Enter something: ")
print("You have entered: " + user_input)
This program will run forever!
this while loop will stop if user enters q
Keep asking until user enters a positive number
Counting even and odd numbers
Green egg and ham?
Green egg and ham?
Comments