# A453 Arithmetic Quiz Task 2

Watch
Announcements
#1
import random#all the questions will be completely random
score = 0#program will calculate their scores(starts with 0)
ops = ['+','-','*']#list of the possible operations the random generator can choose to use for the 10 questions

print("******************************************************************************************************WELCOME TO THE ARITHMETIC QUIZ!!**************************")
print(" ")#for presentation purposes
print(" ")
name=input(" Enter your name:")#python will store the user's name into a variable
print(" Welcome to the Arithmetic Quiz",name,"! Good luck!")#

this part is wrong:

'5B'==class1
'5G'==class2
'5R'==class3

if usersclass==class1:
open("class5B.txt","a+")
if usersclass==class2:
open("class5G.txt","a+")
if usersclass==class3:
open("class5R.txt","a+")

the rest works, apart from the small section above

for i in range(10)this allows the questions to be asked for a total of 10 times
FirstNumber = random.randint(1,15)#all the random numbers generated will range from the numbers 1 to 15
SecondNumber = random.randint(1,15)
operation = random.choice(ops)#random operations will be generated for each question
print(" ")
print(" What does",FirstNumber,operation, SecondNumber,"equal to?")
user = int(input(" Enter your answer:"))#user can give their response to the question

if operation == "+":
answer = FirstNumber + SecondNumber#if the operation is addition, the program will work out the answer taking in this information
elif operation == "-":
elif operation == "*":

print(" That is the correct answer! Keep it up.")#gives the user a message when correct
score = score + 1#with each correct answer, a score is added
else:
print(" That is incorrect. The correct answer is",answer)#gives the user a message when incorrect

print(" ")
print(" Your total score is:",score,"/10")#displays their total score

myfile=open('arithmetic_quiz_results.txt','w')
class1=input("Enter class: ")
myfile.write("Class:" +class1+"\n")
for x in range (1):
name=input("Student's name: \n")
result=input("Score: ")
myfile.write(name +'-'+result)
myfile.close()

That's my coding and If anyone else takes computer science can you please help me? I'm way past my deadline and would like some advice or help with how to do the coding. Thank you
0
5 years ago
#2
(Original post by aliyahh16)
import random#all the questions will be completely random
score = 0#program will calculate their scores(starts with 0)
ops = ['+','-','*']#list of the possible operations the random generator can choose to use for the 10 questions

print("******************************************************************************************************WELCOME TO THE ARITHMETIC QUIZ!!**************************"
print(" "#for presentation purposes
print(" "
name=input(" Enter your name:"#python will store the user's name into a variable
print(" Welcome to the Arithmetic Quiz",name,"! Good luck!"#

this part is wrong:

'5B'==class1
'5G'==class2
'5R'==class3

if usersclass==class1:
open("class5B.txt","a+"
if usersclass==class2:
open("class5G.txt","a+"
if usersclass==class3:
open("class5R.txt","a+"

the rest works, apart from the small section above

for i in range(10)this allows the questions to be asked for a total of 10 times
FirstNumber = random.randint(1,15)#all the random numbers generated will range from the numbers 1 to 15
SecondNumber = random.randint(1,15)
operation = random.choice(ops)#random operations will be generated for each question
print(" "
print(" What does",FirstNumber,operation, SecondNumber,"equal to?"
user = int(input(" Enter your answer:")#user can give their response to the question

if operation == "+":
answer = FirstNumber + SecondNumber#if the operation is addition, the program will work out the answer taking in this information
elif operation == "-":
elif operation == "*":

print(" That is the correct answer! Keep it up."#gives the user a message when correct
score = score + 1#with each correct answer, a score is added
else:
print(" That is incorrect. The correct answer is",answer)#gives the user a message when incorrect

print(" "
print(" Your total score is:",score,"/10"#displays their total score

myfile=open('arithmetic_quiz_results.txt','w'
class1=input("Enter class: "
myfile.write("Class:" +class1+"\n"
for x in range (1):
name=input("Student's name: \n"
result=input("Score: "
myfile.write(name +'-'+result)
myfile.close()

That's my coding and If anyone else takes computer science can you please help me? I'm way past my deadline and would like some advice or help with how to do the coding. Thank you
Is this the quiz one? Where you have to make a quiz? My code is much shorter I think
0
#3
(Original post by zXcodeXz)
Is this the quiz one? Where you have to make a quiz? My code is much shorter I think
yepp, that's the one
maybe mines extra long bc I print out blank spaces for presentational purposes and stuff

What did you for task 2?
i'm trying different things but I don't know how to create 3 different files for the 3 classes so that when the student enters their class, their results are inputted into that particular file
0
5 years ago
#4
(Original post by aliyahh16)
yepp, that's the one
maybe mines extra long bc I print out blank spaces for presentational purposes and stuff

What did you for task 2?
i'm trying different things but I don't know how to create 3 different files for the 3 classes so that when the student enters their class, their results are inputted into that particular file
I'll check online what I wrote and I'll get back to you, by the way have you got the code for task 3?
0
X

new posts
Back
to top
Latest
My Feed

### Oops, nobody has postedin the last few hours.

Why not re-start the conversation?

see more

### See more of what you like onThe Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

### Poll

Join the discussion

#### What is your favourite revision method?

Taking notes manually (53)
21.37%
Note taking apps (6)
2.42%
Flashcards (49)
19.76%
Revision guides (15)
6.05%
Past papers (117)
47.18%
Something else (let us know in the thread) (8)
3.23%