Reputation: 1
I am a beginner to python and coding in general and have not a clue why return in the code below doesn't move across functions. Shouldn't the value for n be stored for use in all functions? print(n) is in there only for my own sake to see if it works, and it is apparently not.
def main():
print("This program tests the Goldbach's conjecture")
get_input()
print(n)
def get_input():
n = 0
while n == 0:
try:
v = int(input("Please enter an even integer larger than 2: "))
if v <= 2:
print("Wrong input!")
continue
if v%2 == 1:
print("Wrong input!")
continue
if v%2 == 0:
n = v
except ValueError:
print("Bad input!")
continue
return n
Upvotes: -1
Views: 33
Reputation: 354
You are not storing the value returned by get_input
anywhere, you should keep it in a variable (or printing it directly), e.g -
def main():
print("This program tests the Goldbach's conjecture")
val = get_input()
print(val)
n
is an internal variable that stored only within the scope of get_input
.
Upvotes: 1