Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def perform_test():
- '''The function begins with a welcome message. Then prompts the user to
- input integers for two things:
- 1) What operation the user would like to be tested on
- (0 for addition and 1 for multiplcation)
- 2) The number of questions they would like to receive
- The test will then produce n questions in the chosen operation.
- If the user answers a question correctly, proceed to the next question.
- If the question is answered incorrectly, inform the user that it is
- incorrect and tell them the correct answer.
- After the test, the results are printed as follows:
- If the final score is >=80%: Excellent work!
- If final score is 60 <= g <= 80: Not bad but you should study more.
- If final score is < 60: You need to practice more'''
- import random
- print('Welcome to the Addition/Multiplication Test!')
- print('Which operation would you like to be tested on?')
- #Prompts user to select operation and number of questions
- test_type = int(input('Input 0 for addition and 1 for multiplication: '))
- #ADDITION TEST
- if test_type == 0:
- n=int(input('Enter the number of questions for the test: '))
- if n==0:
- print('Goodbye')
- exit()
- #Created a total_q variable to serve as a calculation of the
- #overall grade as n will be subtracted by 1 with each new question
- #'correct' is a variable that will increase by 1 with each right answer
- total_q = n
- correct = 0
- #This part will repeatedly display questions until n=0
- while n > 0:
- a=random.randint(0,9)
- b=random.randint(0,9)
- n=n-1
- s=a+b
- print(a,'+',b)
- q=int(input('What is the answer?: '))
- if q == s:
- correct = correct + 1
- else:
- print('Incorrect. The answer is',s,'.')
- if n == 0:
- #grade is the score received after taking the test
- grade = (correct / total_q)*100
- if grade >= 80:
- print('Your grade is',grade,'. Nice work!')
- elif 60 <= grade < 80:
- print('Your grade is',grade,'. Not bad but a little more studying would help.')
- elif grade < 60:
- print('Your grade is',grade,'. You need to study more. Ask your teacher for help.')
- #MULTIPLICATION TEST
- if test_type == 1:
- n=int(input('Enter the number of questions for the test: '))
- if n==0:
- print('Goodbye')
- exit()
- #Created a total_q variable to serve as a calculation of the
- #overall grade as n will be subtracted by 1 with each new question
- #'correct' is a variable that will increase by 1 with each right answer
- total_q = n
- correct = 0
- #This part will repeatedly display questions until n=0
- while n > 0:
- a=random.randint(0,9)
- b=random.randint(0,9)
- n=n-1
- p=a*b
- print(a,'*',b)
- q=int(input('What is the answer?: '))
- if q == p:
- correct = correct + 1
- else:
- print('Incorrect. The answer is',p,'.')
- if n == 0:
- #grade is the score received after taking the test
- grade = (correct / total_q)*100
- if grade >= 80:
- print('Your grade is',grade,'. Nice work!')
- elif 60 <= grade < 80:
- print('Your grade is',grade,'. Not bad but a little more studying would help.')
- elif grade < 60:
- print('Your grade is',grade,'. You need to study more. Ask your teacher for help.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement