I am a complete novice programing, and just started laerning python.
how can i cumulate points in the below program:
import time
import random
while True :
multi_value = random.randint(1, 5)
input_value = random.randint(2, 12)
multi_value_select = int(multi_value)
input_value_select = int(input_value)
print('what is,', multi_value_select, 'x' , input_value_select,'?','....')
correct_answer= int(multi_value_select * input_value_select)
answer=input('Answer = :', )
points= 0
if int(answer) == int(correct_answer):
time.sleep(1)
print('CORRECT :', int(points)+ 2,'pts')
else:
time.sleep(1)
print('WRONG ANSWER')
On line 11, you create points and set it to zero. You want to do that before the loop starts, not inside the loop.
In the if/else, you need to decide on the points, and modify the points
variable. After you modify it, then you can print the current value so the person running can see the total.
Finally, you might want to have some way to end the game. Otherwise it will stay in the loop until the person kills the program.

thanks for the guide bowlofred; i came out with this:
Could it be better?
import time
import random
points = 0
while True :
multi_value = random.randint(1, 5)
input_value = random.randint(2, 12)
multi_value_select = int(multi_value)
input_value_select = int(input_value)
print('what is,', multi_value_select, 'x', input_value_select,'?','....')
correct_answer= int(multi_value_select * input_value_select)
answer=input('Answer = :', )
if correct_answer > 30:
points_value=3
elif correct_answer <30:
points_value=2
if int(answer) == int(correct_answer):
time.sleep(1)
print('CORRECT :', int(points_value),'pts')
Total_points = points + points_value
print('Total pts:',Total_points)
points= Total_points
else:
time.sleep(1)
print('WRONG ANSWER')
Total_points and points are the same thing. You don't need both.
Same thing with multi_value_select and input_vaalue_select. Those are the same thing as multi_value and input_value. You don't need both.
thanks a million.
now
My results shows points achieved out of number of questions. but i want to show 'points achieved from supposed Maximum points'.
with different point values, i am blocked. any

?
import time
import random
points = 0
count= 1
while True:
print('Question:', (count))
print(str('--') * 10)
count = count + 1
multi_value = random.randint(2, 12)
input_value = random.randint(2, 12)
print('what is,', multi_value, 'x', input_value, '?')
correct_answer = int(multi_value * input_value)
answer = input('Answer = :', )
if correct_answer > 30:
points_value = 3
elif correct_answer < 30:
points_value = 2
if int(answer) == int(correct_answer):
time.sleep(1)
print('CORRECT :',points_value, 'pts')
points = points + points_value
else:
print('WRONG ANSWER')
if count == 6:
print(str('--') * 10)
print('\nRESULT\n')
print('You got :', points,'PTS','out of:', count,'questions')
break
print(str('--') * 10)
You'll need a new variable that starts at 0 and to which you add points_value each time.
micseydel
Yessss.
my brother now thinks i'm a gig. for writing a home made mental arithmetic code for his kid.
quite amateur, but i'm thrilled i've reached here, i think i'll hang on thanks to your guides.
import time
import random
points = 0
max_points = 0
count= 1
while True:
print('Question:', (count))
print(str('--') * 10)
count = count + 1
multi_value = random.randint(2, 12)
input_value = random.randint(2, 12)
print('what is,', multi_value, 'x', input_value, '?')
correct_answer = int(multi_value * input_value)
answer = input('Answer = :', )
if correct_answer > 30:
points_value = 3
elif correct_answer < 30:
points_value = 2
if int(answer) == int(correct_answer):
time.sleep(1)
print('CORRECT :',points_value, 'pts')
points = points + points_value
else:
print('WRONG ANSWER')
max_points = max_points + points_value
if count == 6:
print(str('--') * 10)
print('\nRESULT\n')
print('You got :', points,'PTS','out of:', max_points)
break
print(str('--') * 10)