So I was doing a tuition program assignment for homework the other day. This is my program. I hope it's self explanatory. (This is Python, by the way.)
def print_intro():
print ("Welcome to the tuition program. This program will calculate your tuition cost.")
def get_id_num():
grad_status = input("Is the student an undergrad or grad (U/G)? ")
id_num = int(input("Enter the student's ID Number: "))
while (grad_status == "U") and (id_num < 0):
print("Sorry, that is invalid. Please try again.")
id_num = int(input("Enter the student's ID Number: "))
while (grad_status == "G") and (id_num >= 0):
print("Sorry, that is invalid. Please try again.")
id_num = int(input("Enter the student's ID Number: "))
def get_info():
get_id_num()
age = int(input("Enter the student's age (numbers only): "))
residency = input("Is the student in-state or out-of-state (I/O)? ")
num_credits = int(input("How many hours of credit will the student take? "))
correct = input("Is all the above information correct (Y/N)? ")
while correct == "N":
print("Please enter the information correctly!")
get_info()
else:
get_base_tuition()
def get_base_tuition():
if (grad_status == "U") and (num_credits <= 6) and (residency == "I"):
initial_tuition = 2000
if (grad_status == "U") and (7 <= num_credits <= 11) and (residency == "I"):
initial_tuition = 3000
if (grad_status == "U") and (num_credits >= 12) and (residency == "I"):
initial_tuition = 3800
if (grad_status == "U") and (num_credits <= 6) and (residency == "O"):
initial_tuition = 2000
if (grad_status == "U") and (7 <= num_credits <= 11) and (residency == "O"):
initial_tuition = 3000
if (grad_status == "U") and (num_credits >= 12) and (residency == "O"):
initial_tuition = 9000
if (grad_status == "G") and (num_credits <= 6) and (residency == "I"):
initial_tuition = 2000
if (grad_status == "G") and (7 <= num_credits <= 11) and (residency == "I"):
initial_tuition = 2500
if (grad_status == "G") and (num_credits >= 12) and (residency == "I"):
initial_tuition = 4400
if (grad_status == "G") and (num_credits <= 6) and (residency == "O"):
initial_tuition = 2000
if (grad_status == "G") and (7 <= num_credits <= 11) and (residency == "O"):
initial_tuition = 3700
if (grad_status == "G") and (num_credits >= 12) and (residency == "O"):
initial_tuition = 4400
print(initial_tuition)
So after I run this, the get_info() function runs fine, up until it goes to the get_base_tuition() function. I get this error:
line 28, in get_base_tuition
if (grad_status == "U") and (num_credits <= 6) and (residency == "I"):
NameError: name 'grad_status' is not defined
Should I have been adding parameters in my functions or something? I'm stuck and really don't know what to do. I know that if I include the variables "grad_status", "num_credits", and "residency" inside of get_base_tuition() OR define the variables inside the Python Shell before running get_base_tuition(), then of course it will work. But if I put it inside another get_base_tuition() like I did now, it won't work. Is there any way to make the get_base_tuition() function run without having to put the variables inside of get_base_tuition()? Because I already put those variables inside the functions get_id_num() and get_info(). Help is appreciated, thanks.
In case you want to know about the way the base tuition is supposed to be calculated, I attached that assignment here: Assignment Page 2
ifofget_base_tuition. So, your code is too big; before asking, one of your job is to try to trim it to the simplest possible code that still have the problem. And in the same time, it is also too small: because if I copy&paste this code in my terminal, nothing happens. There is no "main code". We don't know which function to call (and we shouldn't have to know).