Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Why is my code not working, i want it so that when points are added or taken away i want them to stay that way(python 3)

+10 votes
asked May 10 by Malachi Johnson (240 points)
This is the code :

name = input("Welcome to the Math Game show I'm your one and only host Miles and what is your name? :")
print ("Nice to see you're here", name, "You will answer 10 questions in 3.....2.....1.....GOOOO!")
question1 = int(input("What is 9 + 10? :"))
points = int(0)
if question1 ==21:
    print("correct here is ten points",points + 10)
elif question1 ==19:
    print("correct here is ten points",points + 10)
else:
    print("incorrect",points - 10, "points")
question2 = int(input("what is 25 x 6? :"))
if question2 ==150:
    print("correct here is ten points",points + 10)
elif question2 ==21:
    print("correct here is ten points",points + 10)
else :
    print("incorrect",points - 10, "points")

this is the output it gave:

Welcome to the Math Game show I'm your one and only host Miles and what is your name? :Mj

Nice to see you're here Mj You will answer 10 questions in 3.....2.....1.....GOOOO!

What is 9 + 10? : 19

correct here is ten points 10

What is 25 x 6? :150

correct here is ten points

4 Answers

0 votes
answered May 11 by Francesco Romano (140 points)
Hi, to answer your question, the game doesn't save points because you're not actually updating them. Basically, when you go to print to increase the score by 10, you're just saying to print the value of the variable points, increasing it by 10. To solve the error I changed the variable containing the score before saying how much it is, and to visualize it a little better I added another line of print to display the total score. Of course you can modify the program to your liking to make it more similar to the idea you have in mind, but I hope I have been of help.
 

The code is this:

name = input("Welcome to the Math Game show I'm your one and only host Miles and what is your name? :")
print ("Nice to see you're here", name, "You will answer 10 questions in 3.....2.....1.....GOOOO!")
question1 = int(input("What is 9 + 10? :"))
points = int(0)
if question1 ==21:
    points += 10
    print("correct here is ten points: +10 points")
    print("Your points: ",points)
elif question1 ==19:
    points += 10
    print("correct here is ten points: +10 points")
    print("Your points: ",points)
else:
    points -= 10
    print("incorrect: -10 points")
question2 = int(input("what is 25 x 6? :"))
if question2 ==150:
    points += 10
    print("correct here is ten points: +10 points")
    print("Your points: ",points)
elif question2 ==21:
    points += 10
    print("correct here is ten points: +10")
    print("Your points: ",points)
else :
    points -= 10
    print("incorrect: -10 points")
    print("Your points: ",points)
+1 vote
answered May 11 by Peter Minarik (72,620 points)
edited May 12 by Peter Minarik

To increase the points stored, you need to tell the compiler about the increment:

points = points + 10

or a shorthand version

points += 10

Then you can print it out, e.g.:

if question2 == 150:
    points += 10
    print("Correct, here is ten points.")

I'm also a bit confused about your logic, why do you grant scores for 9 + 10 = 21?

commented May 11 by ItIsWritten (150 points)
Based on your logic, this should work but I don't understand why 21 should be correct for 10+9

name = input("Welcome to the Math Game show I'm your one and only host Miles and what is your name? :")
print ("Nice to see you're here", name, "You will answer 10 questions in 3.....2.....1.....GOOOO!")

question1 = int(input("What is 9 + 10? :"))
points = int(0)

if question1 == 21 or question1 == 19:
    points += 10
    print("correct here is ten points", points)
else:
    points -= 10
    print("incorrect", points, "points")

question2 = int(input("what is 25 x 6? :"))
if question2 == 150 or question2 == 21:
    points += 10
    print("correct here is ten points", points)
else :
    points -= 10
    print("incorrect", points, "points")
commented May 11 by Malachi Johnson (240 points)
edited May 11 by Malachi Johnson
i see why you are confused on that but that was as a joke for the 9+10 =21 meme
and thanks for the help i will try that
(Thanks so much you just helped me out a bunch thanks for your help!)
0 votes
answered May 11 by vivek (140 points)
name = input("Welcome to the Math Game show I'm your one and only host Miles and what is your name? :")
print ("Nice to see you're here", name, "You will answer 10 questions in 3.....2.....1.....GOOOO!")
question1 = int(input("What is 9 + 10? :"))
points = 0
if question1 ==21:
    points+=10
    print("correct here is ten points",points)
elif question1 ==19:
    points+=10
    print("correct here is ten points",points)
else:
    points-=10
    print("incorrect",points, "points")
print(points)
question2 = int(input("what is 25 x 6? :"))
if question2 ==150:
    points+=10
    print("correct here is ten points",points)
elif question2 ==21:
    points+=10
    print("correct here is ten points",points)
else :
    points-=10
    print("incorrect",points, "points")

this will give u the correct answer
0 votes
answered May 12 by ItIsWritten (150 points)
Based on your logic, this should work but I don't understand why 21 should be correct for 10+9

name = input("Welcome to the Math Game show I'm your one and only host Miles and what is your name? :")
print ("Nice to see you're here", name, "You will answer 10 questions in 3.....2.....1.....GOOOO!")

question1 = int(input("What is 9 + 10? :"))
points = int(0)

if question1 == 21 or question1 == 19:
    points += 10
    print("correct here is ten points", points)
else:
    points -= 10
    print("incorrect", points, "points")

question2 = int(input("what is 25 x 6? :"))
if question2 == 150 or question2 == 21:
    points += 10
    print("correct here is ten points", points)
else :
    points -= 10
    print("incorrect", points, "points")
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...