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)

+12 votes
asked May 10, 2023 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

5 Answers

0 votes
answered May 11, 2023 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, 2023 by Peter Minarik (86,040 points)
edited May 12, 2023 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, 2023 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, 2023 by Malachi Johnson (240 points)
edited May 11, 2023 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, 2023 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, 2023 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")
0 votes
answered Jun 14, 2023 by ZHU MICHAEL 2E-38 (250 points)

There is my code for reference:

name=str(input("Welcome to the Math Game show! I'm your one and the only host Miles! What is your name? "))
print('Nice to meet you,',name+'!')
a=eval(input("How many questions do you want? "))
print("Then please get yourself ready. In 3.....2.....1.....GOOOO!")
list=['+','-','*']
point=0
question=0
for x in range (a):
    import random
    v1=str(random.randint(1,100))
    v2=str(random.randint(1,100))
    v3s=random.randint(0,2)
    v3=list[v3s]
    answer=eval(v1+v3+v2)
    question+=1
    print('Question',str(question)+': What is the answer of',v1+v3+v2,'?')
    A=eval(input())
    if A==answer:
        if v3=='*':
            point+=20
            print('Correct! Since this is a harder question, you just gained 20 points! You now have',point,'points.')
        else:
            point+=10
            print('Correct! You just gained 10 points! You now have',point,'points.')
    else:
        point-=5
        print('Incorrect! The answer is',answer,'! You lose 5 points! You now have',point,'points.')
    print('Now for the next question.')
print('Game over! You answered',question,'questions and your score is',str(point)+'. Well done!')

This can let player answer as much as they want.

In your code, there are some improvements.

1.Never change the variables in print(). If you wish to increase the value of 'point' by 10, you should use point+=10 or point=point+10. If you use print(point+10), the output will be 10 (if 'point' is 0) and variable 'point' does not increase. Note you should assign variables or change them in a new line.

2.Combine if question1==21: and elif question1==19: into if question1==21 or question1==19: . This can make the code more simple. (Though I'm quite confused why 9+10=21 is correct)

3.If you assign a value to a variable, you don't need to use point=int(0) , because 0 is already a number! If you wish to assign a string to a variable, use ' ' , for example, name='Miles' .

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.
...