I’m trying to write something that checks if an integer (z) is within the bounds of x and y, x being the minimum number, y being the maximum. I do this by checking if z is less than the minimum number or more than the maximum number. If either of those are true it returns invalid, else it confirms it. The maximum, minimum and number to check values are determined by raw_input. Here’s the code:
int(x = raw_input('x:\n')) #max number
int(y = raw_input('y:\n')) #min number
int(z = raw_input('z:\n')) #number to check.
if z < y:
print 'invalid.'
elif z > x :
print 'invalid.'
I can enter the x value fine, but when I try to enter the y value, I get this error:
Traceback (most recent call last):
File "C:/Python27/random/bark", line 2, in <module>
int(y = raw_input('y:\n')) #min number
TypeError: 'y' is an invalid keyword argument for this function
I don’t know what I’m doing wrong and I’ve asked elsewhere without answer.
In place of this:
try this:
similarly for the other input statements.
Built-in Python function raw_input() “reads a line from input, converts it to a string “. In order for you to use to use the input as an integer, you need to convert the
stringtointwith the help of the int() function which converts “a string or number to a plain integer”. From your code it looks like you had the basic idea, but your syntax was a bit tangled up.