Lesson 6: While loop and multiplications

posted Nov 21, 2019, 8:04 AM by Attila Lengyel
a = 4
b = 5
print(a * b)

a = int(input("Give me a:"))
b = int(input("Give me b:"))
print(a * b)

import random as r
a = r.randint(0, 10)
b = r.randint(0, 10)
print(a, "*", b, "=", a * b)

a = r.randint(3,20)
b = r.randint(3,20)
task = "What is " + str(a) + " * " + str(b) + "? "
answer = int(input(task))
if answer == a * b:
print("Good job!")
else:
print("Incorrect! It is", a * b)

i = 0
while i < 10:
print(i)
a = r.randint(12,30)
b = r.randint(12,30)
task = "What is " + str(a) + " * " + str(b) + "? "
answer = int(input(task))
if answer == a * b:
print("Good job!")
else:
print("Incorrect. It is ", a * b)
i = i + 1

Comments