Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello, I am a very new beginner of Python GUI. I wrote a very simple script but I am not sure what is wrong with it. Help please.
Python
Score = 0
_question_No = 0
while _question_No != 10:
    num1 = (random.randint (0-10))
    num2 = (random.randint (0-10))
    num3 = (random.randint (1-3))

if num3 == 1:
    print("What is", num1, "+", num2, "?")
    Computer_ans = num1+num2
elif num3 == 2:
    print("What is", num1, "-", num2, "?")
    Computer_ans = num1-num2
else:
    print("What is", num1, "*", num2, "?")
    Computer_ans = num1*num2
User_ans = int(input())
if user_ans == Computer_ans:
    print("Congratulations!")
    score = score +1
else:
    print("Incorrect!")

_question_No = _question_No + 1


Thank you.
Posted
Updated 1-Oct-15 1:21am
v2
Comments
Richard MacCutchan 1-Oct-15 7:20am    
For a start it is not a GUI script. What exactly is the problem?

1 solution

Quite a lot is wrong. You are mis-spelling variables (upper/lower case first letters) so they do not match. And all the code below the first few lines are not correctly indented. The correct version is as follows:
Python
import random
score = 0
_question_No = 0
while _question_No != 10:
    num1 = random.randint (0,10)
    num2 = random.randint (0,10)
    num3 = random.randint (1,3)

    if num3 == 1:
        print("What is", num1, "+", num2, "?")
        Computer_ans = num1+num2
    elif num3 == 2:
        print("What is", num1, "-", num2, "?")
        Computer_ans = num1-num2
    else:
        print("What is", num1, "*", num2, "?")
        Computer_ans = num1*num2
    user_ans = int(input())
    if user_ans == Computer_ans:
        print("Congratulations!")
        score = score +1
    else:
        print("Incorrect!")

    _question_No = _question_No + 1
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900