0

i have variable var, and it is changeable how can i use raw_input and inside raw_input make a question and use this variable i.e.

z = raw_input("Is your age %d') %(var)

but this don't work. Any ideas?

suhailvs
  • 20,182
  • 14
  • 100
  • 98
user
  • 11
  • 1
  • 3

3 Answers3

1

Your code should be:

z = raw_input("Is your age %d" %(var,) )
User
  • 14,131
  • 2
  • 40
  • 59
1

With raw_input, %var should also lie within the parentheses. i.e:

z = raw_input("Is your age %d" % var)
1

I guess the cleanest way is to use format:

z = raw_input("Is your age {0}?".format(var))
Moj
  • 6,137
  • 2
  • 24
  • 36
  • I think this is the best way since it is standart in Python 3 and can be used under Python 3 and Python 2. – User Jun 15 '14 at 17:49