Python uses raw_input with a variable

Can raw_input be used with a variable?

For instance.

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

Thank,

Favolas

+5
source share
4 answers

You can pass anything that evaluates the 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 explicitly turn non-line strings into strings in order to combine them using the str () function.

+9
source

I think it might work

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

another way to do it :)

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

All Articles