+ 1
How to output in straight line when using while loop
6 Answers
+ 1
print("Ra!", end="")
+ 1
# try this code
x=int(input())
if x<1:
print("shh")
elif x>10:
print("High Five")
else:
print("Ra!"*x)
0
What i mean i want the output to be like Ra!Ra!Ra!
0
But my code output it like
Ra!
Ra!
Ra!
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.
0
Thank you (â§âœâŠ)