2016-04-14 152 views
-2

有沒有人知道爲什麼這不起作用? 我試圖製作一個您註冊的程序,它將密碼和用戶名保存到一個文件中,然後登錄到該文件。我沒有完成它,你可以在登錄班級看到,但我跑了一個錯誤:python程序的用戶名和密碼

File "user.py", line 114 
login() 
    ^
IndentationError: expected an indented block 

我真的不知道是什麼錯誤意味着。對不起,當我粘貼代碼,它刪除了空格...

import os 
import time 
from os.path import exists 
import sys #import all the stuff 

def cls():   #define class cls for "clear screen" 
    print("\n"*100) 






def login():  #definr class login 
    print("lolo") 







def register():  #define register 
    username_registered = input("type username:") #asks for a username 

    print("your username is", username_registered) #print's out the  username 



    username_file = open("username.txt", 'w') 

    username_file.write(username_registered)   #writes username to file 




    password_registered = input("type password:")  #asks for a password 

    print("your password is", password_registered) 



    password_file = open("password.txt", 'w') 

    password_file.write(password_registered)   #saves the password 
    menu() 












print("this is a program that you register, it saves the registration, then you login") 
os.system("pause") 
         #draws the menu 
print("""      
----------------------- 
menu 
----------------------- 
1) forward 
2) exit 
----------------------- 
""") 


decision = input("what is your decision:") #asks for a decision 


if(decision != "1" and decision != "2"): #if you tipe something else than 1 or 2 it exits 
    print("error, exiting") 
    time.sleep(2) 
    cls() 
    sys.exit(1) 


if(decision == "2"): #if you chose 2 it exits 
    sys.exit(1) 

x = 0 

while(x != 100):    #draws the loading 
    print("loading", x, "%") 
    x = x + 1 
    time.sleep(0.01) 


time.sleep(0.05) 
print("loading", x, "%") #draws the remaning 100th percent 

time.sleep(1)  #waits a bit 


def menu(): 
    print(""" 
    ------------------------- 
    menu2 
    ------------------------- 
    1) login 
    2) register 
    3) exit 
    -------------------------- 
    """)       #prints the menu2 

    decision = input("what's your decision:") #asks fr a decision 

    if(decision == "1"): #calls login if you tiped 1 
     login() 

    elif(decision == "2"): #calls register if you tiped 2 
     register() 

    elif(decision == "3"):  #exits if you tiped 3 
     sys.exit(1) 

    else:      #terminates if you tiped anything else 
     print("error terminating") 
    time.sleep(2) 
    sys.exit(1) 

    menu() #calls the menu  
+4

你需要學習Python語法的基礎知識。 (特別是縮進) – SLaks

+0

Python使用縮進來幫助將代碼結構化爲[blocks](https://en.wikipedia.org/wiki/Block_%28programming%29)。你的代碼沒有縮進,解釋器會感覺到,結果程序失敗。 – Conduit

+1

錯誤告訴你你需要縮進。什麼不清楚?這實際上是任何Python教程中提到的第一件事情。 –

回答

1

python中的代碼塊必須縮進。 例如,對於cls功能你寫的:

def cls(): 
    print("\n"*100)