有谁知道为什么这不起作用? 我试图制作一个你注册的程序,它将密码和用户名保存到文件中然后你登录到它。我没有完成它,因为你可以在登录类中看到,但我遇到了一个错误:
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
答案 0 :(得分:1)
python中的代码块必须缩进。
例如,对于您编写的cls
函数:
def cls():
print("\n"*100)