Thread: Python Help

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0

    Python Help


    Hi,
    I've been working on a particular math-quiz game as an introductory project to python scripting. In this program, I use strings of random integers to create new problems every time a question comes up.

    However, in one of these chains, the if-then statement that dictates what the program will do depending on if an answer is right or wrong has been malfunctioning. The statement completely bypasses the "correct" option and goes to the "incorrect" route (these are not hard either, its painfully obvious like 8+5=? questions)

    The program piece that is malfunctioning looks like this:

    import random
    Qb=random.randint(1, 10)
    Qbb=random.randint(1, 10)
    print ('Question 2' + str (Qb) +' + ' + str (Qbb) + ' = ?')
    Qba=input()
    Qbaa = Qb + Qbb
    if Qba == ('Qbaa'):
    print ('Correct! + 25 to score!')
    Score = Score + 25
    print (Score)
    else:
    print ('Incorrect')

    What is causing the correct path to be bypassed?
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,704
    Rep Power
    480
    Code:
    # python3
    import random
    Qb=random.randint(1, 10)
    Qbb=random.randint(1, 10)
    print ('Question 2:   ' + str (Qb) +' + ' + str (Qbb) + ' = ?') # separate the question number please!
    Qba=input()      # Qba is a string
    Qbaa = Qb + Qbb  # Qbaa is an integer
    if Qba == str(Qbaa):   # compare as strings.   str(Qbaa)
        print ('Correct! + 25 to score!')
        Score = Score + 25
        print (Score)
    else:
        print ('Incorrect')
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0
    Originally Posted by b49P23TIvg
    Code:
    # python3
    import random
    Qb=random.randint(1, 10)
    Qbb=random.randint(1, 10)
    print ('Question 2:   ' + str (Qb) +' + ' + str (Qbb) + ' = ?') # separate the question number please!
    Qba=input()      # Qba is a string
    Qbaa = Qb + Qbb  # Qbaa is an integer
    if Qba == str(Qbaa):   # compare as strings.   str(Qbaa)
        print ('Correct! + 25 to score!')
        Score = Score + 25
        print (Score)
    else:
        print ('Incorrect')
    Thank you for your help.

IMN logo majestic logo threadwatch logo seochat tools logo