Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python刷新登录系统代码_Python - Fatal编程技术网

Python刷新登录系统代码

Python刷新登录系统代码,python,Python,我正在寻找一种方法,在你选择了你想看的内容(主屏幕选择)之后,不必重新启动程序就可以选择其他内容。这是我的密码 users = [] victims = ['John Smith', 'Karen Jones', 'Kevin Tomlinson'] print ('>>>>> RauCo. Protection Corp. <<<<<') user = input('Username: ') def storeUser(): us

我正在寻找一种方法,在你选择了你想看的内容(主屏幕选择)之后,不必重新启动程序就可以选择其他内容。这是我的密码

users = []
victims = ['John Smith', 'Karen Jones', 'Kevin Tomlinson']
print ('>>>>> RauCo. Protection Corp. <<<<<')
user = input('Username: ')
def storeUser():
  users.append(user)
def check():
  if user == 'Cabbage':
    storeUser()
    print ('Welcome back, Master...')
  else:
    print ('INTRUDER')
    exit()
check()
main_screen_choice = input('What do you want to do? \nVictims, To Do, 
Exit\n(Case Sensitive!): ')
def checkMainChoice():
 if main_screen_choice == 'Victims':
   print (victims)
 elif main_screen_choice == 'To Do':
   print ('Have a shower - you stink!')
 elif main_screen_choice == 'Exit':
   exit()
 else:
   print ('Error: Not a valid option, please run program again')
checkMainChoice()
users=[]
受害者=[“约翰·史密斯”、“凯伦·琼斯”、“凯文·汤姆林森”]

打印('>>>RauCo.Protection Corp.只需重复返回到请求输入并运行相应行为的点

这通常是通过
while
循环实现的。实际上,您的代码如下所示:

while True:
    main_screen_choice = input('What do you want to do? \nVictims, To Do,
        Exit\n(Case Sensitive!): ')
    checkMainChoice()
但我不喜欢全局变量,我建议您为
checkMainChoice
函数指定一个参数:

def checkMainChoice(choice):
    if choice == 'Victims':
        print (victims)
    elif choice == 'To Do':
        print ('Have a shower - you stink!')
    elif choice == 'Exit':
        exit()
    else:
        print ('Error: Not a valid option, please run program again')
然后,
while
循环将变成:

while True:
    main_screen_choice = input(...)
    checkMainChoice(main_screen_choice)

几句话作为旁注:

  • Python中的缩进通常是四个空格。此外,为了使代码可读,您确实需要跳过行
  • Python中的用法是在
    mixedCase
    中命名变量,在
    lower\u case\u中命名方法/函数,并加上下划线
  • 您注意到选项是区分大小写的,这对于这种文本菜单来说并不太合适。您可以通过使用
    lower
    方法将输入设置为小写来轻松解决这个问题:
    choice=input(…).lower()
    。然后,将输入与小写字符串进行比较:
    “to do”
    “exit”

再次调用
input
?了解循环的工作原理,例如,将您的输入打包成一个循环。添加while循环后,当我回答我想做的事情时,它只会再次询问我想做什么do@TylerRauer好吧,如果这不是你想要的,那么你的问题就不是很清楚了