0
My code is wrong but solution is right?
I was doing the exercise where you separate the letter into different lines, and I guess my code is wrong, but the output is exactly the same. What am I doing wrong?
7 odpowiedzi
+ 4
Hi, again.
If A, B and C is a characters, then you have to put quotes around everything like:
print("A\nB\nC\nD")
(If the are variables, the its more complicated:
print(str(A) + "\n" + str(B) + "\n" + str(C) + "\n" + str(D))
but I don’t think they are...)
Another way is this:
print("A", "B", "C", "D", sep="\n")
and same for variables, of course. And maybe the most simple way is to use a for loop, like this:
for c in "ABCB": print(c)
/Regards Per B 🙂
+ 3
Hi!
It’s more easy to help you if you attach a link to your code in your question.
/Regards Per B 🙂
+ 3
if they are variables, just do:
print(A,B,C,D,sep='\n')
+ 2
check for leading/trailing whitespaces: there shouldn't be any in output... and no leading nor trailing new lines to be valid:
print('A\nB\nC\nD')
0
print(A \n B \n C \n D)
0
please show your code.🤭 we don’t know what’s wrong if we can’t even see the code 😬
0
@python_tip @SoloLearn
played with some #code
🤗
yards = int(input())
def cheer(yard):
if yard < 1:
cheers = "shh"
elif 1 <= yard <= 10:
cheers = "Ra!"*yard
elif yard > 10:
cheers = "High Five"
return cheers
c = cheer(yards)
print (c)