Question

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

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import random

S = 0
while(S<=2):
    score = 0
    name = input("Enter your name: ")
    for i in range(3):
        x = random.randint(0,10)
        y = random.randint(0,10)
        z = x+y
        print("Question 1: ",x," + ",y," = ?")
        answer = int(input("Answer :"))
        if answer == z:
            print("good job")
            score = score + 1
        else:
            print("wrong answer")
    file = open(name+'.txt','w')
    file.write("name "+name + " " +"score "+ str(score))
    file.close()
    print(name,", your final score is ",score)
    print("________________")
    S = S + 1

Enter your name: john Question 1 Answer -14 good job Question 1 Answer -23 wrong answer Question 1 Answer -8 good job john, y

Add a comment
Know the answer?
Add Answer to:
Piggy back on the programming project one you completed in module 3. You will use some...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Small Basic Programming Question: Average score Write a program that uses loops to collect data and...

    Small Basic Programming Question: Average score Write a program that uses loops to collect data and calculate the average score over a number of tests for a number of students. The program should : 1. first ask the user to enter the number of students in the range of 1 to 10. 2. then the program asks the user to enter the number of tests (in the range of 1 to 5) 3. Then use a loop to collect the...

  • In this assignment, you will write a program in C++ which uses files and nested loops...

    In this assignment, you will write a program in C++ which uses files and nested loops to create a file from the quiz grades entered by the user, then reads the grades from the file and calculates each student’s average grade and the average quiz grade for the class. Each student takes 6 quizzes (unknown number of students). Use a nested loop to write each student’s quiz grades to a file. Then read the data from the file in order...

  • Small Basic Programming Question: Average Score- Write a program that uses loop to collect data and...

    Small Basic Programming Question: Average Score- Write a program that uses loop to collect data and calculate the average score over a number of tests for a number of students. The program should: 1. first ask the user to enter the number of students in the range of 1 to 10. 2. then the program asks the user to enter the number of tests (in the range of 1 to 5) 3. Then use a loop to collect the scores...

  • C++ Programming

    PROGRAM DESCRIPTIONIn this project, you have to write a C++ program to keep track of grades of students using structures and files.You are provided a data file named student.dat. Open the file to view it. Keep a backup of this file all the time since you will be editing this file in the program and may lose the content.The file has multiple rows—each row represents a student. The data items are in order: last name, first name including any middle...

  • CIS 1111 Programming Files

    Description:In this assignment, you will write a program in C++ that uses files and nested loops to create a file for real estate agents home sales and then read the sales from the file and calculates the average sale for each agent. Each agent sold 4 homes.  Use a nested loop to write each agent’s sales to a file. Then read the data from the file in order to display the agent’s average sale and the average for all sales....

  • Programming in C: Write a program that will help an elementary school student learn multiplication. Use...

    Programming in C: Write a program that will help an elementary school student learn multiplication. Use the random number generator to produce two positive integers between 1 and 12 inclusive. It should then type a question such as:             How much is 6 times 7? The student then types the answer. Your program checks the students’ answer. If it is correct, print a message such as Very good!   If the answer is wrong, print a message such as No. Please...

  • Write a C program to compute average grades for a course. The course records are in...

    Write a C program to compute average grades for a course. The course records are in a single file and are organized according to the following format: Each line contains a student’s first name, then one space, then the student’s last name, then one space, then some number of quiz scores that, if they exist, are separated by one space. Each student will have zero to ten scores, and each score is an integer not greater than 100. Your program...

  • Q3: Write a Python program the prompts the user for information for stu num students. For...

    Q3: Write a Python program the prompts the user for information for stu num students. For each student prompt for the student ID and three quiz grades. Use a nested loop, where the inner loop prompts for the three quiz grades. Print the student's name and average, formatted to two decimal places. The sample output below is when stu_num -3. Enter name of student 1 Mary Jones Enter Score 1: 78 Enter soore 2: 90 Enter soore 3: 91 Name:...

  • In C programming language have a program request the user to enter an uppercase letter. Use...

    In C programming language have a program request the user to enter an uppercase letter. Use nested loops to produce a pyramid pattern like this: The pattern should extend to the character entered. For example, the preceding pattern would result from an input value of E. Hint: Use an outer loop to handle the rows. Use three inner loops in a row, one to handle the spaces, one for printing letters in ascending order, and one for printing letters in...

  • Within DrJava, create a class called StudentQuizScores and do the following using a do-while loop. 1....

    Within DrJava, create a class called StudentQuizScores and do the following using a do-while loop. 1. You program will read in a student’s first name. The same will be done for the student’s last name. Your program will use respective methods (described below) to accomplish this. 2. Your program will then read in three quiz scores, respectively. This should be done by using the same method three times. This method is described below. 3. Your program will then calculate the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT