有谁知道为什么我的函数没有被调用?

时间:2018-11-09 18:48:53

标签: python if-statement

有人知道为什么不调用我的函数吗?每当在我发布的代码部分的底部调用它们时,python都会跳过if和elif并进入其他状态,而当else不在代码中时,shell会变得空闲并等待一个命令

import random
import os
import time


def register():
    uname1 = input('Please enter a username: ')
    pwd1 = input('Please enter a password: ')
    pwdconfirm1 = input('Please Confirm the password: ')
    if pwdconfirm1 == pwd1():
        1cred = open("1Cred.txt","a")
        1cred.write (usernameuser1)
        1cred.write ('\n')
        1cred.write (passworduser1)
        1cred.write("\n")
        1cred.close()
        print('Account created! Please continue to the login page')
    else:
        print('Password does not match!')
        register()


def login():
    print('Login')


print('Welcome to the dice game!')
print('\n')
choice = input('(1) Register\n(2) Login\n')
if choice == 1:
    register()
elif choice == 2:
    login()
else:
    print('Not a valdid input!')

1 个答案:

答案 0 :(得分:0)

将您的内容更改为此:

if choice == '1':
    register()
elif choice == '2':
    login()

1和2是字符串而不是数字。因此,您需要将其用引号引起来。