getMin, getMax = int(input("Enter a range (min,max): "));
Above is the code I am trying to implement but it gives me an error saying...
int() argument must be a string or a number, not 'tuple'
Basically, I have tried entering .split(,) after the input statement but I get the same error. When a user enters 1,10 as an input I want getMin = 1 and getMax = 10
Since you're on Python 2, you should be using raw_input instead of input. Try something like this:
from ast import literal_eval
prompt = "Enter a range (min,max): "
getMin = getMax = None
while {type(getMin), type(getMax)} != {int}:
try:
getMin, getMax = literal_eval(raw_input(prompt))
except (ValueError, TypeError, SyntaxError):
pass # ask again...
IMHO, cleaner approach assuming you want the input to be comma separated
>>> prompt = "Enter a range (min,max): "
>>> while True:
... try:
... getMin, getMax = map(int, raw_input(prompt).split(','))
... break
... except (ValueError, TypeError):
... pass
...
Enter a range (min,max): skfj slfjd
Enter a range (min,max): 232,23123,213
Enter a range (min,max): 12, 432
>>> getMin
12
>>> getMax
432
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With