Reputation: 11
How do I get this all in one line? Do you see a more efficient way to do this as well?
import random
# set the initial values
jersey = random.randint(1, 99)
print ("Who wears jersey no", jersey); input ("?");
The Output is:
Who wears jersey no 11
?
Upvotes: 0
Views: 1732
Reputation: 7225
Anyway, one alternative different from the above:
input ("Who wears jersey no %s ?" % random.randint(1, 99));
Upvotes: 0
Reputation: 1190
Not sure that having it all on one line is preferable, but you could do:
import random
a = raw_input('Who wears jersey no {}? '.format(random.randint(1,99)))
Upvotes: 0
Reputation: 26397
You can just do something like,
input("Who wears jersey no {}?".format(random.randint(1, 99)))
But don't stress about making one-liners all the time. Readability is important and if that means using multiple lines, do that instead.
Upvotes: 1