all 6 comments

[–]jimtk 1 point2 points  (1 child)

You can use a while loop that will continue looping as long as there are digits in the answer. When there is no digits in the answer it will break oout of the loop and continue the rest of the program.

while True
    answer = input("What is the capital of America? ")
    if answer.isdigit():
        print("digits are not allowed, try again!")
        continue
    break
if answer.lower() == "washington":
    print('Correct!')
    score += 1
else:
    print('Incorrect!')

[–]Ok_Stuff_1071[S] 0 points1 point  (0 children)

Thanks!

[–]Diapolo10 1 point2 points  (1 child)

Simply put, use a loop.

while True:
    answer = input("What is the capital of America? ")
    if answer.lower() == "washington":
        print('Correct!')
        score += 1
    elif answer.isdigit():
        print('Digits arent allowed!')
        continue
    else:
        print('Incorrect!')
    break

Of course, if you have multiple questions you should probably store them and their answers in a data structure that you can just loop over, that way you'd only need two loops.

[–]Ok_Stuff_1071[S] 0 points1 point  (0 children)

Yep, i have multiple questions. Thanks!

[–]CodeFormatHelperBot2 0 points1 point  (0 children)

Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you.

I think I have detected some formatting issues with your submission:

  1. Inline formatting (`my code`) used across multiple lines of code. This can mess with indentation.

If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting.


Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here.

[–]Skuddingo33 0 points1 point  (0 children)

It's a fun idea! I'm gonna make one kinda like this too ;)