Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Piggy back on the programming project one you completed in module 3. You will use some of those concepts here again. We will be building

Piggy back on the programming project one you completed in module 3. You will use some of

those concepts here again. We will be building this project inside out, start individual quiz and

use a for loop to repeat it three times for three students.

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

Notes:

In this project you will be using 2 for loops. One an inner loop in green and then the outer loop

in yellow. Inner loops creates the individual questions for one student

Outer loop repeats the process of designing three quizzes and saving each quiz as a text file

with just the name and the final score

The first test is to do the inner loop in green including importing the random number and

creating the score variable. This should work by itself.

Then add the outer loop in yellow.

When you run the program here is how your output should look like, I used the multiplication

operator, you should use the addition operator but the screen should look similar to this image.

and also check the folder where you saved your program, the same folder should contain three

.txt files with the filename + 1, 2 and 3 added to the file name. See the screen shot below. I only

have two txt files, you should have three since you are running the loop three times.

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions