samedi 9 janvier 2016

Calling a Function from an 'If' statement

I am using Python 3, and have encountered an error when trying to call a function from an if statement, the following code is a simplified version of the full code but has the same result and I am wandering how to overcome this and allow the program to run the student() function

import sys

def logon():
    print("Welcome, please enter your account type")
    acctype = input()
    if acctype == 'teacher':
        sys.exit()
    elif acctype == 'student':
        student()

logon()


def student():
    print("Please enter your name") 
    name = input()

    print("Please enter your class number")
    classnumber = input()

The problem occurs after inputting a the word student, as the error returns

NameError: name 'student' is not defined

Aucun commentaire:

Enregistrer un commentaire