Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- from os.path import exists
- from time import sleep
- def points(username, points):
- with open(username+"points", 'a') as k:
- k.write(points)
- def rgen():
- return random.randrange(3, 10)
- def others(area): # function rid
- print("others")
- if random.randrange(0,1):
- print("others 1")
- o= area+random.randrange(1, (area/10)+1)
- else:
- print("others 2")
- o= area-random.randrange(1, (area/10)+1)
- return o
- def tra(length, height):
- return (length*height)/2
- def rea(length, height):
- return length*height
- def game():
- while True:
- uf= input('Enter shape (rectangle/triangle) or menu to return to menu: ').lower()
- if uf == "menu":
- break
- elif uf == 'triangle':
- rh= rgen(); rl= rgen()
- ra= float(tra(rh, rl))
- elif uf == 'rectangle':
- rh= rgen()
- rl= rgen()
- while rl==rh:
- rl= rgen()
- ra= float(rea(rl, rh))
- else:
- print("Enter one of the options")
- continue
- l=[] # working
- #print(l) # working
- l.append(float(ra))
- #print(l) # working
- while len(l) <= 3:
- #sleep(0.9)
- #print("while len l")
- #print(bool(len(l) < 5))
- if random.randrange(0, 2):
- #print("others 1")
- #try:
- v = ra + random.randrange(1, ((ra / 5)//1) + 3)
- #except Exception as e:
- #print(e)
- #print("true", v)
- else:
- #print("others 2")
- #try:
- v = ra - random.randrange(1, ((ra / 5)//1) + 3)
- #except Exception as e:
- #print(e)
- #print(v, "oth2")
- if v not in l:
- #sleep(1)
- #print(l, "tofore")
- l.append(float(v))
- #print(l, "appended v")
- """
- while len(l) < 5:
- print("while len(l) <= 4")
- v= others(ra)
- print(l)
- if v not in l:
- print("if v not in l")
- l.append(v)
- print(v)"""
- random.shuffle(l)
- print("Random shuffled")
- print('''Length: %i
- Height: %i
- Which of the following is the area: %a''' % (rl, rh, l))
- while True:
- try:
- ug= float(input())
- if ug not in l:
- print('Enter one of the options')
- continue
- if ug == ra:
- points(ue, '2\n')
- break
- else:
- while True:
- try:
- uh = float(input("Try again: "))
- if uh not in l:
- print("Enter one of the options")
- continue
- if uh == ug:
- print("Enter a different option")
- continue
- if uh == ra:
- points(ue, '1\n')
- break
- else:
- print("Wrong, Answer was %i" % ra)
- except ValueError:
- print("Enter one of the options")
- continue
- break
- except ValueError:
- print ("Enter one of the options")
- continue
- break
- def wpoints(username):
- k=open(username+"points", "w")
- k.close()
- def pwc(password, filename): #password correct
- if open(filename).read() == password:
- return True
- else: return False
- def wusername(username):
- # create file with pw+username
- fn= 'pw'+username
- k=open(fn, 'w')
- k.close()
- return fn # return file name of user
- def wpassword(password, filename):
- # add in wusername created file username's password
- with open(filename, 'w+') as k:
- k.write(password)
- k.close()
- def signin():
- global ue
- while True:
- ue= input('Enter username: ')
- if exists('pw'+ue):
- break
- else:
- print('Enter correct username')
- continue
- while True:
- uf= input("Enter password for user %s" % ue)
- if pwc(uf, 'pw'+ue):
- break
- else:
- print("Incorrect password. Try again.")
- continue
- game()
- def cacc():
- uc= input("Enter username: ")
- while True:
- ud= input('Enter password: ')
- if len(ud) < 8 or len(ud) > 18:
- print("Password must be between 8 and 18 characters")
- continue
- if not any(d.isdigit() for d in ud) or not any(d.isalpha() for d in ud):
- print("Must contain letters and numbers")
- continue
- if not any(d.isupper() for d in ud) or not any(d.islower() for d in ud):
- print("Must contain upper and lower case")
- continue
- break
- try:
- fun= wusername(uc)
- wpassword(ud, fun)
- wpoints(uc)
- except IOError:
- print('System cannot write to files; application will now close')
- quit()
- def choice():
- while True:
- ub= input("Do you have an account? (yes/no)").lower()
- if ub == 'yes':
- signin()
- elif ub == 'no':
- cacc()
- else:
- print("Enter either yes or no")
- continue
- break
- def vscore():
- while True:
- ui= input("View score for which user/return to menu: ")
- if ui.lower() == "menu": break
- if not exists(ui+"points"):
- print("Account does not exist/ points file does not exist for user")
- else:
- k= open(ui+"points").read()
- d=k.split('\n')
- print("Points: %i" % sum(list(map(int, d))))
- break
- while True:
- while True:
- try:
- ua= int(input('''Do you wish to:
- 1. Sign in
- 2. View score
- 3. Quit'''))
- if ua == 1:
- choice()
- elif ua == 2:
- vscore()
- elif ua == 3:
- break
- else:
- print("Enter a valid value")
- continue
- except ValueError:
- print("Enter one of the options")
- continue
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement