forked from accakks/Simple-Programs-in-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpowersof2.py
More file actions
26 lines (20 loc) · 762 Bytes
/
powersof2.py
File metadata and controls
26 lines (20 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import random
# I created this as a way to practice powers of 2 for a CS class
def powerof2():
keep_going = True
userRange = input("What range of powers of 2? ")
userRange = int(userRange)
while keep_going:
for i in range(userRange):
power = random.randint(0,10)
ans = int(input("What is 2**" + str(power) + ": "))
correct = 2**power
if ans == correct:
print("Correct!")
else:
print("Wrong!")
print(str(correct))
keep_going = input("Would you like to play again? (True or False)")
userRange = input("What range of powers of 2? ")
userRange = int(userRange)
powerof2()