Hello. So, I have just started learning Python and now I would like some help.
The code works but there is a space after the last random generated number, how to remove that space?
print('What is',random.randrange(1, 11),'times',random.randrange(1, 11),'?')
Example: What is 3 times 2 ?
Is lstrip() something useable here?
Your have a print statement with commas that generate blank spaces, formatting gives more control.
Perhaps you are looking for this:
print('What is {} times {}?'.format(random.randrange(1, 11),random.randrange(1, 11)))
Paul
(Jun-06-2020, 06:44 AM)DPaul Wrote: [ -> ]Your have a print statement with commas that generate blank spaces, formatting gives more control.
Perhaps you are looking for this:
print('What is {} times {}?'.format(random.randrange(1, 11),random.randrange(1, 11)))
Paul
Oh, thanks for fast reply, it works great. Interesting with .format, will read and test more.
(Jun-06-2020, 07:01 AM)rs74 Wrote: [ -> ]Oh, thanks for fast reply, it works great. Interesting with .format, will read and test more.
.format()
is starting to get old,there is now
f-string.
from random import randrange
print(f'What is {randrange(1, 11)} times {randrange(1, 11)}?')
Output:
What is 4 times 1?