Reputation: 33
I'm writing a script that is asking for user to input a number between 1-10, the script will then call the function Size
and will return true
if the number is greater or equal to 5
and false
if not. However, I seem to have run into a bit of a wall, I get an error asking me to define x, this is my code currently.
def Size(x):
if x >= 5:
print("True")
else:
print("False")
x = int(input("Please enter a number greater than 5"))
Size(x)
Upvotes: 1
Views: 1281
Reputation: 3121
You declared user input x in the Size function. X should be an outside size function
def Size(x):
if x >= 5:
print("True")
else:
print("False")
x = int(input("Please enter a number greater than 5"))
Size(x)
Or if you want to take user input in Size function then initialize x in Size function and pass just Size function then follow the second answer
Upvotes: 3
Reputation: 33
def Size(x):
if x >= 5:
print("True")
else:
print("False")
x = int(input("Please enter a number greater than 5"))
Size(x)
The error occured because I didn't fix my indentation after the false statement.
Upvotes: 0
Reputation: 133458
You were close, you need to correct 3 things in your code.
funcSize
.
#!/usr/bin/python3
def funcSize():
x = int(input("Please enter a number greater than 5: "))
if x >= 5:
print("True")
else:
print("False")
funcSize()
Upvotes: 3