-1

I am trying to print number dynamically.

I tried it according to this answer

I want to print something like: numbers: 1 2 3 4 5

but instead it is printing: numbers: 63 numbers: 25 numbers: 57 numbers: 43 numbers: 9

here is my code:

a= range(1,53)
for i in xrange(5):
    b = a[random.randint(0,len(a)-i)]
    a.remove(b)
    print "Your numbers:", b,

I know problem is , after string.

How to fix it?

Community
  • 1
  • 1
Freddy
  • 2,216
  • 3
  • 31
  • 34

1 Answers1

0

You should only print'Your numbers' string before the for loop , and print the actual numbers inside, your current code prints 'Your numbers' for each number.

Example -

print "Your numbers:",
for i in xrange(5):
    b = a[random.randint(0,len(a)-i)]
    a.remove(b)
    print b,
Anand S Kumar
  • 88,551
  • 18
  • 188
  • 176
  • Thanks that worked. But as always there are downvotes. I think down vote are only if I ask some question without research effort or showing my own efforts. – Freddy Aug 02 '15 at 06:58