Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please read each sentence don\'t skip anything full answer its a full credit som

ID: 3624638 • Letter: P

Question

please read each sentence don't skip anything full answer its a full credit
sometime some people answer some and they don't complete the task.




Python code for the following programming problem based on the problem definition below. Use modular design according to the suggested modules below.

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 that are to be subtracted.

247
- 129

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.

In addition to any built-in functions you may use, you might consider the following functions:
• A function that allows the student to enter their name.
• A function that gets two random numbers, anywhere from 1 to 500.
• A function that displays the equation (*for extra credit, either addition or subtraction) and asks the user to enter their answer.
• A function that checks to see if the answer is right and accumulates the number right.
• A function that calculates the results.
• A function that displays the student name, the number right, and the average right.

Your sample output might look as follows (random numbers will be different):

Enter Student Name: Katie
What is the answer to the following equation
424
-
28
What is the answer: 394
Wrong

What is the answer to the following equation
163
-
233
What is the answer: -70
Right

What is the answer to the following equation
285
-
453
What is the answer: 168
Wrong

Etc…(through 10 iterations)

Information for student: Katie
The number right: 5
The average right is 0.50 or 50.0 %

*EXTRA CREDIT: (+25 points)
Program the problem to present an addition or subtraction at random depending upon a code generated at random…a code=0 can represent a subtraction equation and code=1 can represent an addition problem.

Explanation / Answer

import random
def main():
    name = raw_input("Enter Student Name: ")
    numCorrect = 0.0
    totalProblems = 10
    for i in range(totalProblems):
        # presentProblem will return 1 or 0 depending on student's answer
        numCorrect += presentProblem()
        print
    print "Information for student: %s"%name
    print "The number right: %d"%numCorrect
    printAverage(numCorrect,totalProblems)

# Show the student's average if they got a certain fraction correct
# Takes as arguments the number of correct responses and the total number of problems
def printAverage(numCorrect,totalProblems):
    fractionCorrect = numCorrect / totalProblems
    print "The average right is %.02f or %.01f %%"%(fractionCorrect,fractionCorrect*100)

#Present an addition or subtraction problem
# and check the student's answer
#Return 0 if incorrect and 1 if correct
def presentProblem():
    print "What is the answer to the following equation"
    num1 = random.randrange(1,501)
    num2 = random.randrange(1,501)
    op = random.choice(["-","+"])
    if op == "-":
        ans = num1-num2
    else:
        ans = num1+num2
    print num1
    print op
    print num2
    studentAns = int(raw_input("What is the answer: "))
    if studentAns == ans:
        print "Right"
        return 1
    else:
        print "Wrong"
        return 0

if __name__ == "__main__":
    main()