python - 我的项目不断让我退出,为什么会这样?(关闭)
问题描述
我正在编写一个代码,允许我将数据保存到数据库中。但是由于某种原因,每当我输入响应时,它都会引用 else 语句并将我注销。
这是我的代码:
username = "storagei"
password = "something"
# asking for a username and password.
userInput = input("welcome back to safespace! Please type in your username to access your data.\n")
if userInput == username:
userInput = input("Password?\n")
if userInput == password:
print("Welcome back to safespace Izzy!")
else:
print("That is the wrong password. Please try again.")
exit(1)
else:
print("There is no username that matches what your responce. Please try again.")
exit(2)
print "You can open_storage, add_to_storage, or log_out"
userInput = input("What would you like to do?\n")
log_out = "Thanks for using safespace. Come back soon!"
open_storage = "opening files."
add_to_storage = "what do you like to add?"
if userInput == log_out:
print("Thanks for using safespace. Come back soon!")
exit(3)
if userInput == open_storage:
print("opening storage. Please wait...")
if userInput == add_to_storage:
print("what would you like to add?")
else:
print("not a valid input. Logging you out.")
所以出于某种原因,当它到达这部分代码时:
print "You can open_storage, add_to_storage, or log_out"
userInput = input("What would you like to do?\n")
log_out = "Thanks for using safespace. Come back soon!"
open_storage = "opening files."
add_to_storage = "what do you like to add?"
if userInput == log_out:
print("Thanks for using safespace. Come back soon!")
exit(3)
if userInput == open_storage:
print("opening storage. Please wait...")
if userInput == add_to_storage:
print("what would you like to add?")
else:
print("not a valid input. Logging you out.")
我自己修复了我的代码。如果您想查看它们,这是我拥有的所有编辑的工作脚本。
username = "storagei"
password = "something"
# asking for a username and password.
userInput = input("welcome back to safespace! Please type in your username to access your data.\n")
if userInput == username:
userInput = input("Password?\n")
if userInput == password:
print("Welcome back to safespace Izzy!")
else:
print("That is the wrong password. Please try again.")
exit(1)
else:
print("There is no username that matches what your responce. Please try again.")
exit(2)
print "You can open_storage type in o. add_to_storage type in a. log_out type in l. delete_files type in d. or edit_files type in e."
userInput = input("What would you like to do?\n")
l = "l"
o = "o"
a = "a"
d = "d"
e = "e"
if userInput == l:
print("Thanks for using safespace. Come back soon!")
exit(3)
if userInput == o:
print("opening storage. Please wait...")
if userInput == a:
print("what would you like to add?")
if userInput == d:
print("what file do you want to delete?")
if userInput == e:
print("what file do you want to edit?")
else:
if userInput != l:
if userInput != o:
if userInput != a:
if userInput != d:
if userInput != e:
print("not a valid input. Logging you out.")
解决方案
尝试这个
if userInput == 'open_storage':
print("opening storage. Please wait...")
elif userInput == 'add_to_storage':
print("what would you like to add?")
elif userInput == 'log_out':
print("Thanks for using safespace. Come back soon!")
exit(3)
else:
print("not a valid input. Logging you out.")
推荐阅读
- amazon-web-services - 部署自动化的最佳方式
- google-cloud-firestore - 谁能告诉为什么在输入文档数据后无法启用此保存按钮?
- analytics - 是否有我们可以在刷新时跟踪的 ETL 报告?
- neural-network - 由 PyTorch 中的数字 (csv) 组成的自己的数据集
- bash - 检查日期格式是否为 bash 中的 ISO 8601
- r - r 无法安装 rstan r 版本 4.1.0 ubuntu 20.04.2
- apache-spark-sql - 具有正常功能的 ADB 笔记本“Package cell”在没有导入的情况下无法正常工作
- java - 如何使用 json api 查找附近的地方(使用非 google-places-api 服务)
- python - 在引导 python 烧瓶中获取下拉选择的值
- python - Numpy - 如何生成以下 n 维矩阵