我正在Python上编写一个非常基本的支付系统,但每次输入main()函数并输入一个值时,它都会退出程序。有任何想法吗?函数不会继续
import sys
def info():
usernames = ["15mermelstein_p","gril","jeff","example"]
passwords = ["test","pass","what","why"]
balances = [22.91,45.76,21.62,7.54]
a = input("What is your username? ").lower()
b = input("What is your password? ")
print(a)
print(b)
success = 0
for index in range(len(usernames)):
if usernames[index] == a and passwords[index] == b:
user_num = index
success = 1
break
if success == 1:
print("Login successful\n")
main()
return (a,b,user_num)
else:
print("Login unsuccessful")
info()
def main():
choice = input("-----Welcome to the new School Payment System-----\n1. Add money to account\n2. Change password\n3. Change your username\n4. Quit the program\n--------------------------------------------------\n")
if choice == "1":
credit = input("How much money would you like to deposit into your account? ")
temp_b = input("Please type in your password once againto confirm thios transaction: ")
if temp_b == info[2]:
balances[num(info[3])] += float(credit)
else:
print("The password you entered was incorrect, please return and try again. ")
elif choice == "2":
check_pass = input("Please input your current password first")
elif choice == "3":
sys.exit(0)
elif choice == "4":
sys.exit(0)
else:
sys.exit(0)
info()
您需要告诉我们更多...您提供什么输入,您是否在第一次输入后看到任何内容,或者是否在第一次输入后立即结束。另外,独立于您的选择,程序将在'main()'结束后结束。 –
开始调试问题的一个好方法是打印出您正在测试的值的repr(例如,'print(repr(choice))'),这是有人给您发现的或者您发现并修改为python3的代码你的需要,你正在运行Python 2(即使你标记了这个python3x)...也许在你的其他分支中找出一个print statemetn来找出你要出错的地方 –
读取错误信息,然后查找函数范围 – user3080953