Favolas
Favolas

Reputation: 7243

Python use raw_input with a variable

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

Answers (4)

NickCortes
NickCortes

Reputation: 111

one more way to do it :)

value = raw_input('Please enter a value between 10 and %i for percentage' % (max))

Upvotes: 1

Derrick
Derrick

Reputation: 155

i think this might work

value = input('Please enter a value between 10 and {} for percentage'.format(max))

Upvotes: 1

D.C.
D.C.

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

Related Questions