The issue I'm having is that in one of my functions ( function range_and_number()
), I'm asking the user for input, and I'm saving this input in a variable called max number
. Next I checked to make sure that this value only has numbers in it, and if it does I break the loop.
def range_and_number():
while True:
max_number = input("Max Number Possible (No Decimals): ")
if max_number.isnumeric() == True:
print("Your Good")
max_number = int(max_number)
break
else:
print("Please Re-Type Your Maximum Number: ")
return max_number
def get_length():
lives = len(range_and_number)
return lives
def main():
s = get_length()
print(f"================= {s} =================")
Issue: I want to access the value of max number
in another function ( function get_length()
) because in this function, I want to measure the length of characters in the variable 'max number'.
The error I'm getting is:
lives = len(range_and_number)
TypeError: object of type 'function' has no len()
I understand why I'm getting the error, but how do I get around it. How do I access the value stored in max_number
without calling the function itself.
P.S. If you have the time, please post as many possible solutions please. Thanks in advance
(What I tried)
- I tried using a Global Variable and created it at the top of my function
- I named the Global Variable TE
- Then, I did
TE = max_number
- After, I tried accessing TE in the second function, but it didn't work