The Student Room Group

A453 Arithmetic Quiz Task 2

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:

usersclass=int(input("Enter your class:5B,5G or 5R"))
'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):colonhash: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 == "-":
answer = FirstNumber - SecondNumber
elif operation == "*":
answer = FirstNumber *SecondNumber



if user == answer:
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
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!!**************************":wink:
print(" ":wink:#for presentation purposes
print(" ":wink:
name=input(" Enter your name:":wink:#python will store the user's name into a variable
print(" Welcome to the Arithmetic Quiz",name,"! Good luck!":wink:#


this part is wrong:

usersclass=int(input("Enter your class:5B,5G or 5R":wink:)
'5B'==class1
'5G'==class2
'5R'==class3

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

the rest works, apart from the small section above





for i in range(10):colonhash: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(" ":wink:
print(" What does",FirstNumber,operation, SecondNumber,"equal to?":wink:
user = int(input(" Enter your answer:":wink:)#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 == "-":
answer = FirstNumber - SecondNumber
elif operation == "*":
answer = FirstNumber *SecondNumber



if user == answer:
print(" That is the correct answer! Keep it up.":wink:#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(" ":wink:
print(" Your total score is:",score,"/10":wink:#displays their total score


myfile=open('arithmetic_quiz_results.txt','w':wink:
class1=input("Enter class: ":wink:
myfile.write("Class:" +class1+"\n":wink:
for x in range (1):
name=input("Student's name: \n":wink:
result=input("Score: ":wink:
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
Reply 2
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
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?

Quick Reply

Latest