0

I dont understand how to make lasting changes to variables.

I am writing a program for fun that is a quiz. When an answer is correct, the program has a func that is this. print("you have gotten" , r+1 , "question(s) correct out of" , t+1") . It works how i want it for the first question, but after i move to the next one, i do not know how to make the computer recognize that i want to keep the values assigned to r and t. Meaning i want r and t to have 1 unit added to them before the next question to show progress. r represents correct answers and t represents total questions asked. Thank you for any input!

21st Oct 2016, 9:36 PM
Ari
4 Respuestas
0
r += 1 is the same as r = r + 1 (it increments r by 1) meaning the value of r changes. r+1 doesnt assign the new value to r, so the value of r stays the same. r += 1 t += 1 print(r + " right out of" + t)
22nd Oct 2016, 1:00 AM
Luke Armstrong
0
Ok thank you!!
22nd Oct 2016, 1:00 AM
Ari
- 1
use r +=1 and t +=1 before your print statement. then dont include the +1 in the print statement.
22nd Oct 2016, 12:47 AM
Luke Armstrong
- 1
When i tried that, it gave me an error, ill keep trying though, thanks for the advice
22nd Oct 2016, 12:55 AM
Ari