-1

Does any one know why my functions are not being called? When ever it goes to call them at the bottom of the section of code i posted, python just skips the if and elif and goes strait to else, and when else isn't in the code, the shell just goes idle and waits for a command

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!')
  • 2
    `"1" == 1` -- ? Not in Python! (So, the simplest explanation for the behavior was that the conditional expressions were not being evaluated to true and.. wala!) – user2864740 Nov 09 '18 at 18:50

1 Answers1

0

Change your if to this:

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

1 and 2 are strings not numbers. So you need to enclose it in quotes.

Mayank Porwal
  • 33,470
  • 8
  • 37
  • 58