I was wondering why this won't work? I'm fairly new to programming and I'm learning Python.
def convert(x,y):
while True:
try:
global x
x = int(input("Number: "))
except ValueError:
print("Make sure it is a number.")
while True:
try:
global y
y = int(input("Number: "))
except ValueError:
print("Make sure it is a number.")
convert(x,y)
Please tell me how to make this work.
Also, the error I get when I run this is name 'x' is parameter and global.
Ok, I fixed it. This is the correct code.
def convert():
while True:
try:
global number
number = int(input("Number: "))
break
except ValueError:
print("Make sure it is a number.")
while True:
try:
global number2
number2 = int(input("Number: "))
break
except ValueError:
print("Make sure it is a number.")
convert()
x
andy
are you passing the function when you call it? Also, you don't appear to be using them in the function, so what their purpose? – Lawlessx
andy
global? They're not used outside of the enclosing scope. – Octant