Hey can I get some help please? I forgot how to do this
Additionally, I wanted to add in a sort of ‘failsafe’ so that way if someone types something other than a number, it says “Please only use numbers” and then asks the question again. Thanks!
print("Welcome to the Times Tables Game!")
print()
print("How well do you know your times tables? Pick a number and I will test you on its first 10 multiples.")
print()
number = int(input("Choose your number: "))
print()
counter = 0
for i in range(1, 11):
correct_answer = i*number
print(i, "x", number)
answer = int(input("> "))
if answer == correct_answer and counter == 1:
print("You got it right!")
counter += 1
if answer == correct_answer and counter == 2:
print("Awesome!")
counter += 1
if answer == correct_answer and counter == 3:
print("Great Job!")
counter += 1
if answer == correct_answer and counter == 4:
print("Fantastic!")
counter += 1
if answer == correct_answer and counter == 5:
print("Amazing!")
counter += 1
if answer == correct_answer and counter == 6:
print("Keep Going!")
counter += 1
if answer == correct_answer and counter == 7:
print("Great Work!")
counter += 1
if answer == correct_answer and counter == 8:
print("Almost there!")
counter += 1
if answer == correct_answer and counter == 9:
print("Incredible!")
counter += 1
else:
print("That's not correct. It should have been", correct_answer)
if counter == 10:
print("Wow! A perfect score! 🥳")
else:
print(f"You got {counter} out of 10 correct.")
from firepup650 import input # Yes, it overwrites default, I need to change that.
# EX 1:
number = input("Choose your number:", int, "Please only use numbers")
# EX 2:
answer = input("> ", int, "Please only use numbers")
number = input("Gimme a number right now\n")
if number.isint():
print("thanks")
else:
number = input("try again")
IIRC that works. Put that in a function. Or use something like this (which I know works):
def get_ur_number(message):
while True:
try: number = int(input(message)); break
except: Pass
I am just making this up as I go to give a rough guideline. I have a function for stuff like this in my package but it’s based on something flamongo wrote.
user = input("Username please? ")
match user:
case "Qwerty" | "Bobby":
print("You are not allowed to access the database!")
case "python660":
print("You are allowed to access the database!")
data = db.get("Rishabh")
print(data)
case _:
print("You are not a company member , you are not \
allowed to access the code !")
I dont that would work because that is specific to user. I just want it to progress. So the first correct answer says “You got it right!” and then the second would say “Awesome!” or smth like that
One thing I notice right away is that counter initializes to 0, but there’s no case for 0 in the match statement. Also, the match statement should probably have a default case (_).