Favolas Favolas - 2 months ago 11
Python Question

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

Answer

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.