Reputation: 7243
Is it possible to use raw_input with a variable?
For example.
max = 100
value = raw_input('Please enter a value between 10 and' max 'for percentage')
Thanks,
Favolas
Upvotes: 5
Views: 26612
Reputation: 111
one more way to do it :)
value = raw_input('Please enter a value between 10 and %i for percentage' % (max))
Upvotes: 1
Reputation: 155
i think this might work
value = input('Please enter a value between 10 and {} for percentage'.format(max))
Upvotes: 1
Reputation: 799230
Python Language Reference, §5.6.2, "String Formatting Operations"
Upvotes: 2
Reputation: 15588
You can pass anything that evaluates to a string as a parameter:
value = raw_input('Please enter a value between 10 and' + str(max) + 'for percentage')
use + to concatenate string objects. You also need to explicitely turn non-strings into string to concatenate them using the str() function.
Upvotes: 10