Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cumulating results
#1
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')
Reply
#2
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.
Reply
#3
Idea thanks for the guide bowlofred; i came out with this:
Could it be better? Think

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')
Reply
#4
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.
Reply
#5
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 Idea ?
Confused

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)
Reply
#6
You'll need a new variable that starts at 0 and to which you add points_value each time.
Reply
#7
micseydel
Yessss. Clap
my brother now thinks i'm a gig. for writing a home made mental arithmetic code for his kid. Big Grin
quite amateur, but i'm thrilled i've reached here, i think i'll hang on thanks to your guides. Wink

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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Search Results Web results Printing the number of days in a given month and year afefDXCTN 1 2,231 Aug-21-2020, 12:20 PM
Last Post: DeaD_EyE
  How to append one function1 results to function2 results SriRajesh 5 3,141 Jan-02-2020, 12:11 PM
Last Post: Killertjuh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020