+ 1

How to output in straight line when using while loop

https://code.sololearn.com/chpVf4YV8mt5/?ref=app

23rd Apr 2022, 1:23 AM
Aisy Danish Mohd Nazry
Aisy Danish Mohd Nazry - avatar
6 Answers
+ 1
print("Ra!", end="")
23rd Apr 2022, 1:27 AM
Simon Sauter
Simon Sauter - avatar
+ 1
# try this code x=int(input()) if x<1: print("shh") elif x>10: print("High Five") else: print("Ra!"*x)
23rd Apr 2022, 1:29 AM
SoloProg
SoloProg - avatar
0
What i mean i want the output to be like Ra!Ra!Ra!
23rd Apr 2022, 1:25 AM
Aisy Danish Mohd Nazry
Aisy Danish Mohd Nazry - avatar
0
But my code output it like Ra! Ra! Ra!
23rd Apr 2022, 1:25 AM
Aisy Danish Mohd Nazry
Aisy Danish Mohd Nazry - avatar
0
Aisy Danish Mohd Nazry You already got the solution from Simon Sauter , so I'll just add some comments: 1. Your while loop has all conditions known at the beginning. So you can simplify by changing it to a for loop. 2. The "high five" condition is the same in every loop iteration, so you can save CPU by putting the if test before the loop. This requires rethinking the logic, what is great for learning. 3. Study string operators. Specially '*'. This is a very simple code, and these changes won't make much difference. But what you'll learn will improve significantly when writing big stuff.
23rd Apr 2022, 1:58 AM
Emerson Prado
Emerson Prado - avatar
0
Thank you (≧▜≊)
23rd Apr 2022, 2:43 AM
Aisy Danish Mohd Nazry
Aisy Danish Mohd Nazry - avatar