Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this program you will be required to write a python program that generates math quizzes for students in second grade. Your program should do

In this program you will be required to write a python program that generates math quizzes for

students in second grade. Your program should do the following

Ask the student for their name

Provide 3 addition problems, very simple with just 2 numbers, x + by, where x and y are 2

random numbers generated by the random number generator in the range 1 to 10

Each time the addition answer is correct, you update the score for the student and write it out

to the file with the student name and score.

After the three problems are completed for the first student, you repeat this for the second

student and then the third student.

Here is one way to design your program. This program uses two for loops. One to create the file

to record student name and score. The second is an inner for loop to generate the actual quiz.

Note the indentations in the template I have given. The first for loop Is not indented and the

second one and its steps are indented. Python is very picky on indentation so pay attention to

that.

Import random number library

Have a variable called total or score or any other name to keep track of the score for each

student

# This part is the outer part of the program, it uses a for loop to create three files

#that keeps track of the student names and their total scores for the quiz

# with three questions

Have a list variable to store the files for each student, since you need it for three students say

something like qf[3]

Now use the for loop to iterate through the steps of

for q in range(3)

Getting a students name and save it in a variable

Open a file qf in append mode to record the students name and score. One point to

note is that you need to save the file with a unique name. The easy way to do it is to

use a place holder with the % sign after the file name. So

qf = open(qf%s.txt % (q +1), a)

# This portion of the program is designing the quiz with three questions

# and check if the answers are accurate

Initialize your score to 0

Use a for loop to generate the actual quiz for x in range (3)

For x in range[3]

Use the random number generator to generate the first number and print

Use the random number generator to generate the second number and print

Prompt the user to answer what is number 1 + number 2

Save the answer in a variable

Do an if test to check if the answer is correct

If correct, print good job, increment the score, else give an appropriate message

like sorry

Print the final score

Write students name to the file qf

Write the score to the file qf

Close the file qf

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions