2016-04-14 118 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)