Trying this question again for the 5th time (Sample Run included)....
Currently we are on Chapter 5 of Pearson's Starting out with PYTHON (Functions)
Write a program that will allow a student to enter their name and then ask them to solve 10 mathematical equations. The program should display two random numbers (from 1 - 500) that are to be added:
Sample run 1:
Enter Student Name: Katie
What is the answer to the following equation? 99 + 221
What is the sum: 435
Wrong
What is the answer to the following equation? 134 + 44
What is the sum: 174
Wrong
What is the answer to the following equation? 408 + 238
What is the sum: 646
Right
What is the answer to the following equation? 222 + 180
What is the sum: 400
Wrong
Information for student: Katie
The number right: 3
The average right is 0.30 or 30.0 %
-> The program should allow the student to enter the answer. The program should then display whether the answer was right or wrong and accumulate the correct values.
-> After the 10 questions are asked, calculate the average correct. Then display the student name, the number correct, and the average correct in both decimal and percentage format.
import random #import random package for get random numbers using randint method
# random_equation function
def random_equation():
student_name = input("Enter Student Name: ") # get Student name
from user
i=0 #this variable is used while loop exit
right = 0 #this variable is used count right answer
# while loop for 10 Questions
while i<10: #check i variable is less than 10
num1 = random.randint(1,500) #get first random number in between
1-500
num2 = random.randint(1,500) #get second random number in between
1-500
print("What is the answer to the following
equation?",num1,"+",num2) #Print equation with two random
numbers
add = num1 + num2 # add variable is stored correct addition of two
random numbers
add_no = int(input("What is the sum: ")) # get answer from user to
sum of two random numbers
if add == add_no: #check correct addition and user enter sum is
match
right += 1 # then user enter rigth answer increment right variable
by one
print("Right") #Print right message
else:
print("Wrong") #Print Wrong message
i += 1 # i is increment by one upto i less than 10
print("")
print("Information of student: ",student_name) #Print student
name
print("The number right: ",right) #Print count of right
answer
average = (right/10)*100 #calculate average in percentage
format
#Print average in decimal and percentage format first is decimal
and second is percentage format
print("The average right is: ",(right/10),"or",average,"%")
random_equation() # call random_equation function
==================================OUTPUT==========================
==Please Upvote==
Get Answers For Free
Most questions answered within 1 hours.