• API
• FAQ
• Tools
• Trends
• Archive
daily pastebin goal
9%
SHARE
TWEET

zenetico Apr 8th, 2017 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. def perform_test():
2.     '''The function begins with a welcome message. Then prompts the user to
3.     input integers for two things:
4.     1) What operation the user would like to be tested on
5.     (0 for addition and 1 for multiplcation)
6.     2) The number of questions they would like to receive
7.
8.     The test will then produce n questions in the chosen operation.
9.     If the user answers a question correctly, proceed to the next question.
10.     If the question is answered incorrectly, inform the user that it is
11.     incorrect and tell them the correct answer.
12.
13.     After the test, the results are printed as follows:
14.     If the final score is >=80%: Excellent work!
15.     If final score is 60 <= g <= 80: Not bad but you should study more.
16.     If final score is < 60: You need to practice more'''
17.
18.     import random
19.     print('Welcome to the Addition/Multiplication Test!')
20.     print('Which operation would you like to be tested on?')
21.     #Prompts user to select operation and number of questions
22.     test_type = int(input('Input 0 for addition and 1 for multiplication: '))
23.
25.     if test_type == 0:
26.         n=int(input('Enter the number of questions for the test: '))
27.         if n==0:
28.             print('Goodbye')
29.             exit()
30.         #Created a total_q variable to serve as a calculation of the
31.         #overall grade as n will be subtracted by 1 with each new question
32.         #'correct' is a variable that will increase by 1 with each right answer
33.         total_q = n
34.         correct = 0
35.
36.         #This part will repeatedly display questions until n=0
37.         while n > 0:
38.             a=random.randint(0,9)
39.             b=random.randint(0,9)
40.             n=n-1
41.             s=a+b
42.             print(a,'+',b)
43.             q=int(input('What is the answer?: '))
44.             if q == s:
45.                 correct = correct + 1
46.             else:
48.
49.         if n == 0:
51.             grade = (correct / total_q)*100
54.         elif 60 <= grade < 80:
58.
59. #MULTIPLICATION TEST
60.     if test_type == 1:
61.         n=int(input('Enter the number of questions for the test: '))
62.         if n==0:
63.             print('Goodbye')
64.             exit()
65.         #Created a total_q variable to serve as a calculation of the
66.         #overall grade as n will be subtracted by 1 with each new question
67.         #'correct' is a variable that will increase by 1 with each right answer
68.         total_q = n
69.         correct = 0
70.
71.         #This part will repeatedly display questions until n=0
72.         while n > 0:
73.             a=random.randint(0,9)
74.             b=random.randint(0,9)
75.             n=n-1
76.             p=a*b
77.             print(a,'*',b)
78.             q=int(input('What is the answer?: '))
79.             if q == p:
80.                 correct = correct + 1
81.             else:
83.
84.         if n == 0: