Python Forum
controlled assessment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
controlled assessment
#1
hi, i am doing a mock controlled assessment in computer science, in which i am allowed to do research outside of the lesson, so doing this is breaking no rules. In the program that i have been asked to create, i need to create a piece of code where i have to let the user register, log in, and add there scores to their account. I also need to make sure that when a user is registering, they are not using a name that has already been used. I know that to do this i need to read and write from a text file. I've tried the answers that google and other websites are giving me, but i just get logic or syntax errors. Has anyone got any advice on what type of file i use or how to do any of this?
thanks
ps,( i dont know how the link works where you can put your code in, i'm trying, if it doesn't work, i apologise)

Attempt together no1 

###############################
##      Area Trainer         ##
##                           ##
##            ##
##                           ##
##       15/06/17            ##
##                           ##
###############################

#importing random fundtion and setting score to 0
import random
score=0
#printing menu
print("Welcome to the aea trainer, would y0u like to:")
print("1)practice the area of a circle")
print("2)practice the area of a rectangle")
print("3)practice the area of a triangle")
print("4)See your previous scores")
print("5)quit the program")
#lets the user make a choice on what they want to do
choice= int(input("Please select the number of the activity you want to do:  "))
#rectangle
if choice==2:
   #generates two numbers randomly between 1 and 100
   num1= random.randint(1,100)
   num2= random.randint(1,100)
   #tells the user the dimensions
   print ("A rectangle with the dimensions",num1,num2)
   #works out the right answer
   rightanswer=num1*num2
   #gets three numbers:
   #one to add on
   #One to take away
   #and one to multiply by the correct answer
   #this prouduces three wrong answers
   addon=random.randint(1,10)
   takeoff=random.randint(1,10)
   timesby=random.randint(1,10)
   #does the equations and produces three wrong answers
   wronganswer1=rightanswer+addon
   wronganswer2=rightanswer-takeoff
   wronganswer3=rightanswer*timesby
   #puts four answers into an array
   answers= [rightanswer,wronganswer1,wronganswer2,wronganswer3]
   print ("Here are your answers")
   #########
   #answer1#
   #########
   answerone=answers[random.randint(0,3)]
   print ("1)",answerone)
   answers.remove(answerone)
   #########
   #answer2#
   #########
   answertwo=answers[random.randint(0,2)]
   print ("2)",answertwo)
   answers.remove(answertwo)
   #########
   #answer3#
   #########
   answerthree=answers[random.randint(0,1)]
   print ("3)",answerthree)
   answers.remove(answerthree)
   #########
   #answer4#
   #########
   answerfour=answers[0]
   print ("4)",answerfour)
   answers.remove(answerfour)
#triangle
elif choice==3:
   num1= random.randint(1,100)
   num2= random.randint(1,100)
   print ("A triangle with the dimensions",num1,num2)
   rightanswer=num1*num2/2
   addon=random.randint(1,10)
   takeoff=random.randint(1,10)
   timesby=random.randint(1,10)
   wronganswer1=rightanswer+addon
   wronganswer2=rightanswer-takeoff
   wronganswer3=rightanswer*timesby
   answers= [rightanswer,wronganswer1,wronganswer2,wronganswer3]
   print ("Here are your answers")
   #answer1
   answerone=answers[random.randint(0,3)]
   print ("1)",answerone)
   answers.remove(answerone)
   #answer2
   answertwo=answers[random.randint(0,2)]
   print ("2)",answertwo)
   answers.remove(answertwo)
   #answer3
   answerthree=answers[random.randint(0,1)]
   print ("3)",answerthree)
   answers.remove(answerthree)
   #answer4
   answerfour=answers[0]
   print ("4)",answerfour)
   answers.remove(answerfour)
elif choice== 1:
   num1= random.randint(1,100)
   print("You will need a calculator for this")
   print("Also, pi in this equation= 3.14!")
   print ("A circle with a radius",num1)
   rightanswer= 3.14*num1
   addon=random.randint(1,10)
   takeoff=random.randint(1,10)
   timesby=random.randint(1,10)
   wronganswer1=rightanswer+addon
   wronganswer2=rightanswer-takeoff
   wronganswer3=rightanswer*timesby
   answers= [rightanswer,wronganswer1,wronganswer2,wronganswer3]
   print ("Here are your answers")
   #answer1
   answerone=answers[random.randint(0,3)]
   print ("1)",answerone)
   answers.remove(answerone)
   #answer2
   answertwo=answers[random.randint(0,2)]
   print ("2)",answertwo)
   answers.remove(answertwo)
   #answer3
   answerthree=answers[random.randint(0,1)]
   print ("3)",answerthree)
   answers.remove(answerthree)
   #answer4
   answerfour=answers[0]
   print ("4)",answerfour)
   answers.remove(answerfour)
chosenvalue= float(input("Please type the answer that you think is correct"))
#scoring system
#if you get it right first try
if chosenvalue==rightanswer:
   print("Well done! You got it first try, Two points added to your total!")
   #adding points to a pre-determined score
   score=score+2
#if the user gets it wrong first try    
else:
   print ("Sorry, incorrect, but you still have one more try!")
   print("here are your answers again")
   #user chooses a second answer
   chosenvalue2= float(input("Please type your second answer in"))
   #if the second answer is right
   if chosenvalue2==rightanswer:
       print("Well done! You got it second try, one points added to your total!")
       #adding one to the users score
       score=score+1
       #if user still gets answer wrong
   else:
       #prints right answer
       print("Unlucky! The right answer was",rightanswer)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Sentinel Controlled Loop adrury2 3 3,147 Mar-12-2019, 10:27 PM
Last Post: adrury2

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020