Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from os.path import join
- import random
- import math
- def triangle(score, username):
- count = 0
- length1 = random.randint(1,101)
- length2 = random.randint(2,101)
- areaTri = (length1 * length2) / 2
- areaTri = int(areaTri)
- wrong1 = areaTri + (random.randint(1,21))
- wrong2 = areaTri - (random.randint(1,21))
- while wrong2 < 0:
- wrong2 = areaTri - (random.randint(1,21))
- print("""
- The triangle has a length of {} and a width of {}""".format(length1, length2))
- list1 = [wrong1, areaTri, wrong2]
- random.shuffle(list1)
- print1 = list1[0]
- print2 = list1[1]
- print3 = list1[2]
- userSelect = int(input("""
- What is the area of the triangle?
- {}
- {}
- {}
- """.format(print1, print2, print3)))
- if userSelect == areaTri:
- print("correct")
- score = score + 2
- retry = str(input("""do you want to continue?
- Y/N?
- """))
- while count < 1:
- if retry == "Y" or "y":
- triangle(score, username)
- count = count + 1
- elif retry == "N" or "n":
- print("your score was {}".format(score))
- count = count + 1
- mainShapeMenu(username)
- else:
- print("Sorry, that option is invalid")
- else:
- print("sorry, that was incorrect, try again")
- userSelect = int(input("""
- What is the area of the triangle?
- {}
- {}
- {}
- """.format(print1, print2, print3)))
- if userSelect == areaTri:
- print("correct")
- score = score + 1
- retry = str(input("""do you want to continue?
- Y/N?
- """))
- while count < 1:
- if retry == "Y" or "y":
- triangle(score, username)
- count = count + 1
- elif retry == "N" or "n":
- print("your score was {}".format(score))
- count = count + 1
- mainShapeMenu(username)
- else:
- print("Sorry, that option is invalid")
- else:
- print("Sorry, you answered incorrectly twice, the correct answer was {}, your final score was {}".format(areaTri, score))
- triCheck = open("{}triSave.txt".format(username), "r")
- triSave = open("{}triSave.txt".format(username), "w")
- score = str(score)
- triSave.write(score)
- mainShapeMenu(username)
- def rectangle(score, username):
- count = 0
- length1 = random.randint(1,101)
- length2 = random.randint(2,101)
- areaRec = (length1 * length2)
- areaRec = int(areaRec)
- wrong1 = areaRec + (random.randint(1,21))
- wrong2 = areaRec - (random.randint(1,21))
- while wrong2 < 0:
- wrong2 = areaRec - (random.randint(1,21))
- print("""
- The rectangle has a length of {} and a width of {}""".format(length1, length2))
- list1 = [wrong1, areaRec, wrong2]
- random.shuffle(list1)
- print1 = list1[0]
- print2 = list1[1]
- print3 = list1[2]
- userSelect = int(input("""
- What is the area of the triangle?
- {}
- {}
- {}
- """.format(print1, print2, print3)))
- if userSelect == areaRec:
- print("correct")
- score = score + 2
- retry = str(input("""do you want to continue?
- Y/N?
- """))
- while count < 1:
- if retry == "Y" or "y":
- rectangle(score, username)
- count = count + 1
- elif retry == "N" or "n":
- print("your score was {}".format(score))
- count = count + 1
- mainShapeMenu(username)
- else:
- print("Sorry, that option is invalid")
- else:
- print("sorry, that was incorrect, try again")
- userSelect = int(input("""
- What is the area of the rectangle?
- {}
- {}
- {}
- """.format(print1, print2, print3)))
- if userSelect == areaRec:
- print("correct")
- score = score + 1
- retry = str(input("""do you want to continue?
- Y/N?
- """))
- while count < 1:
- if retry == "Y" or "y":
- rectangle(score, username)
- count = count + 1
- elif retry == "N" or "n":
- print("your score was {}".format(score))
- count = count + 1
- mainShapeMenu(username)
- else:
- print("Sorry, that option is invalid")
- else:
- print("Sorry, you answered incorrectly twice, the correct answer was {}, your final score was {}".format(areaRec, score))
- recCheck = open("{}recSave.txt".format(username), "r")
- recSave = open("{}recSave.txt".format(username), "w")
- score = str(score)
- recSave.write(score)
- mainShapeMenu(username)
- def circle(score, username):
- count = 0
- length1 = random.randint(1,101)
- areaCirc = (math.pi * length1)^2
- areaCirc = int(areaCirc)
- wrong1 = areaCirc + (random.randint(1,21))
- wrong2 = areaCirc - (random.randint(1,21))
- while wrong2 < 0:
- wrong2 = areaCirc - (random.randint(1,21))
- print("""
- The circle has a radius of {}""".format(length1))
- randomSelect1 = random.randint(0,3)
- randomSelect2 = random.randint(0,2)
- list1 = [wrong1, areaCirc, wrong2]
- print1 = list1[randomSelect1]
- list.remove(print1)
- print2 = list1[randomSelect2]
- list.remove(print2)
- print3 = list1[0]
- userSelect = int(input("""
- What is the area of the circle?
- {}
- {}
- {}
- """.format(print1, print2, print3)))
- if userSelect == areaCirc:
- print("correct")
- score = score + 2
- retry = str(input("""do you want to continue?
- Y/N?
- """))
- while count < 1:
- if retry == "Y" or "y":
- circle(score, username)
- count = count + 1
- elif retry == "N" or "n":
- print("your score was {}".format(score))
- count = count + 1
- mainShapeMenu(username)
- else:
- print("Sorry, that option is invalid")
- else:
- print("sorry, that was incorrect, try again")
- userSelect = int(input("""
- What is the area of the circle?
- {}
- {}
- {}
- """.format(print1, print2, print3)))
- if userSelect == areaCirc:
- print("correct")
- score = score + 1
- retry = str(input("""do you want to continue?
- Y/N?
- """))
- while count < 1:
- if retry == "Y" or "y":
- circle(score, username)
- count = count + 1
- elif retry == "N" or "n":
- print("your score was {}".format(score))
- count = count + 1
- mainShapeMenu(username)
- else:
- print("Sorry, that option is invalid")
- else:
- print("Sorry, you answered incorrectly twice, the correct answer was {}, your final score was {}".format(areaCirc, score))
- circCheck = open("{}circSave.txt".format(username), "r")
- circSave = open("{}circSave.txt".format(username), "w")
- score = str(score)
- circSave.write(score)
- mainShapeMenu(username)
- def login():
- usernameLocal = str(input("what is your username?"))
- saveFile = open("loginDetails{}.txt".format(usernameLocal))
- passwordLocal = str(input("What is your password? (this is case sensitive)"))
- saveFilePassword = saveFile.readlines()
- saveFilePassword2 = saveFilePassword[1]
- print(saveFilePassword)
- length = len(saveFilePassword)
- passLength = len(passwordLocal)
- passAscii = []
- passAscii2 = []
- count = 0
- for i in range(length):
- saveFileAscii = ord(saveFilePassword2[i])
- passAscii.append(saveFileAscii)
- for i in range(passLength):
- userPassAscii = ord(passwordLocal[i])
- passAscii2.append(userPassAscii)
- for i in range(length):
- if passAscii[i] == passAscii2[i]:
- count = count + 1
- else:
- pass
- if count == length:
- username = usernameLocal
- print("all is good")
- mainShapeMenu(username)
- else:
- print("sorry, that password doesn't match")
- login()
- def registerSave(username,password):
- # filePath = join("C:", "Users", "Louis", "My Documents", "loginDetails.txt")
- usernameLocal = username
- savePath = ("loginDetails{}.txt".format(usernameLocal))
- registerLogin = open(savePath, "w")
- registerLogin.write("{}\n{}".format(usernameLocal, password))
- registerLogin.close()
- def usernameCreate():
- username = str(input("what would you like you username to be? "))
- passwordCreate(username)
- def passwordCreate(username):
- password = str(input("What would you like your password to be? "))
- passLen = len(password)
- passwordAscii = []
- for i in range(passLen):
- asciiCheck = password[i]
- passwordAscii.append(ord(asciiCheck))
- print(passwordAscii)
- count = 0
- if passLen < 8:
- print("sorry, your password is too short")
- passwordCreate(username)
- else:
- for i in range(passLen):
- passwordCheck = password[i]
- if passwordCheck.isupper() == True:
- count = count + 1
- else:
- pass
- if count > 0:
- registerSave(username,password)
- fileCreate(username)
- mainShapeMenu(username)
- #insert save function
- else :
- print("sorry, your password contains no capitals")
- passwordCreate(username)
- def fileCreate(username):
- save1 = open("{}circSave.txt".format(username), "w")
- save1.close
- save2 = open("{}recSave.txt".format(username), "w")
- save2.close
- save3 = open("{}triSave.txt".format(username), "w")
- save3.close
- def start():
- startRequest = int(input("""
- 1. Register
- 2. Login
- """))
- if startRequest == 1:
- usernameCreate()
- else:
- login()
- def mainShapeMenu(username):
- shapeSelect = int(input("""
- What shape do you want to practise?
- 1. Triangle
- 2. Rectangle
- 3. Circle
- 4. Exit"""))
- if shapeSelect == 1 or "triangle" or "Triangle":
- score = 0
- triangle(score, username)
- elif shapeSelect == 2 or "rectangle" or "Rectangle":
- score = 0
- rectangle(score, username)
- elif shapeSelect == 3 or "circle" or "Circle":
- score = 0
- circle(score, username)
- elif shapeSelect == 4 or "exit":
- sys.exit
- else:
- print("Sorry, that is not an option")
- mainShapeMenu()
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement