Search code examples
pythonraw-input

How to use a raw_input value in a line for taking input in python


I want to take input as string as raw_input and want to use this value in another line for taking the input in python. My code is below:

p1 = raw_input('Enter the name of Player 1 :')
p2 = raw_input('Enter the name of Player 2 :')


p1 = input('Welcome %s > Enter your no:') % p1

Here in place of %s I want to put the value of p1.

Thanks in advance.


Solution

  • You can do (the vast majority will agree that this is the best way):

    p1 = input('Welcome {0} > Enter your no:'.format(p1))