2016-07-08 114 views
0
def LoginScreen(): 
    global User_Points 
    User_Points = 5 
    print("Welcome to Area Trainer") 
    print("Please enter the username for your account") 
    global user_name 
    user_name = str(input()) 
    save = open(user_name + '.txt', 'w') 
    points = open(user_name + 'Score' + '.txt', 'w+') 
    points.write(str(User_Points)) 


    PasswordCheck= True 
    while PasswordCheck: 
     user_password = input("type in your password: ") 
     if len(user_password) < 8: 
      print("your password must be 8 characters long") 
     elif not any(i.isdigit() for i in user_password): 
      print("you need a number in your password") 
     elif not any(i.isupper() for i in user_password): 
      print("you need a capital letter in your password") 
     elif not any(i.islower() for i in user_password): 
      print("you need a lowercase letter in your password") 
     else: 
      PasswordCheck = False 



def MenuTriangle(): 
    global User_Points 
    print('''Here is a triangle with a height of 12cm and a width of 29cm 
    /\  |    *Not to scale. 
/\ | 
/ \ | 12cm 
/ \ | 
<-------> 
    29cm 
    You must find out the area and select the correct answer from these options''') 
    print('''A) 175 
     B) 174 
     C) 2000 
     D) 199 

      ''') 
    user_input = input().upper() 

    if user_input == "A": 
      print("I'm sorry this is incorrect but you still have a chance to get 1 point!") 
      MenuTriangle2() 

    elif user_input == "C": 
      print("I'm sorry this is incorrect but you still have a chance to get 1 point!") 
      MenuTriangle2() 

    elif user_input == "D": 
      print("I'm sorry this is incorrect but you still have a chance to get 1 point!") 
      MenuTriangle2() 

    elif user_input == "B": 
      print("Congratulations! You got it right, someone's a smart cookie. Here have two points!") 
      reading = open(user_name + 'Score' + '.txt') 
      score = reading.read() 
      score = int(score) + 2 
      print("Your score is", score) 
      points = open('ok' + 'Score' + '.txt', 'w+') 
      points.write(str(score)) 
      MenuStart() 

def MenuStart(): 

    print("Welcome to the mathematical area game!") 
    print("In this game you will be required to calculate the area of multiple shapes.") 
    print("To do this you must know how to calculate the area of different shapes with increasing difficulty") 
print('''Please select a shape you want to play, 
    A) Triangle 
    B) Square 
    C) Circle''') 
user_input = input().upper() 

    if user_input == "A": 
     print("You have chosen to calculate the area of a triangle!") 
     MenuTriangle() 

    elif user_input == "B": 
     print("You have chosen to calculate the area of a square!") 
     MenuSquare() 

    elif user_input == "C": 
     print("You have chosen the calculate the area of a circle!") 
     MenuCircle() 

    else: 
     print("Oops! I didn't understand that >:") 
     MenuStart() 




LoginScreen() 
MenuStart() 

你好,我想做一个小游戏,用户必须猜测形状的区域是什么,如果他们得到它的权利,然后他们得到2分,但是,我正在使用外部文件来存储游戏的分数,但是每当我通过输入我的名字玩游戏时,密码我都会看到分数的值在我得到答案后会变为2,但是当它调用菜单函数时在文件中的分数被重置,我不知道为什么游戏中的得分系统。 PYTHON 3.5

正确的答案来保存按下按钮是B 现在可用的唯一选项是三角形。如果任何人都可以请解决这个问题,将不胜感激。

回答

0

这是因为Python每次打开时都会自动覆盖文件中的数据。您通过多次调用该函数多次打开该文件。

+0

我不知道如何做这个评分系统,那么,有什么想法? – BushellsMaster