I am trying to get col_number and user_input to be recognized outside of the input function.
The only way I seem to be able to use the col_number outside the input function is if I define a global variable inside - which doesn't seem right. I have tried placing the statement above the def get_input but get a 'col_number might be referenced before assignment.
I need to use the user_input as a txt string for a header on a graph but don't understand how to pass it out. The print statement last line in the code gives me an unresolved reference.
Any suggestions please.
col_number = int
def get_input(prompt):
#global col_number
#locals col_number
global col_number
while True:
user_input = input(prompt).lower()
if user_input in ('apples', 'pears', 'oranges', 'quit'):
# the user = int(0),int(1), int(2) values just assign a different column numnber
if user_input == 'apples':
col_number = 0
if user_input == 'pears':
col_number = 1
if user_input == 'oranges':
col_number = 2
return col_number, user_input
print(get_input(prompt='Enter apples, pears, oranges or q to quit'))
print(user_input)
col_number = intisn't what you think it is, it looks like you're trying to reassign the typeinttocol_number. Did you meancol_number = int()?col_number: int