Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions powersof2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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()