Home > Software design >  How do I may a simple statement if not ABCD error message. Also I am having problems getting the num
How do I may a simple statement if not ABCD error message. Also I am having problems getting the num

Time:07-27

I am new to python and am trying to do two things that are not working.

The first is return the number of questions a person asks for (I have got my error messages done.

The second I want an error message if the user does not enter exactly A,or B,or C, or D. I have set it so they can't leave it blank and tried to do it so that if they enter a number they get an error message. I just want to add that they can't add characters or letters e-z or lower case.

def playquiz(): 
    print ("How many questions would you like to answer?")
    numberofquests =input()
    numberofquests = int(numberofquests)

    if numberofquests > 15:
     print ("there aren't that many questions. The maximum you can answer is 15!")
     print ("How many questions would you like to answer?")
     numberofquests =input()
     numberofquests = int(numberofquests)

    if numberofquests <=0:
     print ("Good bye")
     exit (0)
     
playquiz()


# -------------------------
def new_game():
    
              
    guesses = []
    correct_guesses = 0
    question_num = 1


    for key in questions:
        print("-------------------------")
        print(key)
        for i in options[question_num-1]:
            print(i)
        guess = input("Enter (A, B, C, or D): ")
        guess = guess.upper()
        guesses.append(guess)

        while guess ==(""):
            print ("Can't leave this empty")
            guess = input("Enter (A, B, C, or D): ")

        while guess == isalpha():
            print ("You must enter either A,B,C,D")

        correct_guesses  = check_answer(questions.get(key), guess)
        question_num  = 1

    display_score(correct_guesses, guesses)

CodePudding user response:

use the numberofquests = int(input("How many questions would you like to answer?"))

numberofquests = int(input("How many questions would you like to answer?")) print(numberofquests)

  • Related