Day 21 Challenge

Hey can I get some help please? I forgot how to do this :skull:

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.")
1 Like

My package has a good thing for that :slight_smile:
EX:

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")
3 Likes

Why did you post here and not Ask? You’d get much more help on Ask

quoting that here ples stop disliking my post

1 Like
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.

2 Likes

image

maybe I should have mentioned because Ask has a category and topics dedicated to 100 DoC…

2 Likes

How do I make it to where it says a different message after each correct answer?

  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

doesnt work

1 Like

Make all of those but the first one elif.

3 Likes

smh, i won’t consider it a gud package until it’s in js

1 Like

But you see:

My package gives you console in Python.

2 Likes

Yes firepup’s package is the Python knock-off of JS so that JS people can use the slower Python. I guess it gives them Flask.

2 Likes

image

also there isnt supposed to be an indent in the code snippet, i just fixed it

try using match case

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 !")
2 Likes

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

Unless you can do match counter?

Can you do case counter == 1

you can do

match counter:
    case 1:
        print("Option 1")
1 Like


:noooooooooooooooooooo:

What did I do wrong

no python :annoyed:

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 (_).

2 Likes

:frowning:
why not?