0

Please help me...There is a problem which is named "cheer creator".Its level is easy. I write the code but isn't accepted.

yard = int(input()) if yard > 10 : print ("High five") elif yard < 1 : print ("shh") else : for i in range(yard) : print ("Ra!")

22nd Jul 2023, 10:48 AM
Samin Mirabbaszadeh
Samin Mirabbaszadeh - avatar
4 Answers
+ 6
1- First of all, you need to change "High five" to "High Five" with capital F because the problem wants you to do that! 2- print function adds a new line after every output, so when the yard is 3, your code output is -> Ra! Ra! Ra! But the problem wants you this -> Ra!Ra!Ra! To fix this, you can change your print function to not add a new line after each print -> print("Ra!", end = "") Alternatively, you can store the string in a variable first, and after that, print it -> else: result = "" for i in range(yard) result += "Ra!" print(result)
22nd Jul 2023, 11:43 AM
Mohammad Ebrahimi
Mohammad Ebrahimi - avatar
+ 6
Samin Mirabbaszadeh, I would add another idea to Mohammad's excellent answer. Because you are working in Python, you can take advantage of its unusual feature of string multiplication. Multiplying a string by an integer, like "Hello"*n, easily replicates the string n times. If n is 3, the result will be "HelloHelloHello".
22nd Jul 2023, 1:51 PM
Brian
Brian - avatar
+ 3
Thanks â˜ș
22nd Jul 2023, 11:48 AM
Samin Mirabbaszadeh
Samin Mirabbaszadeh - avatar
+ 1
Thank you because of your great advice 💖
22nd Jul 2023, 2:19 PM
Samin Mirabbaszadeh
Samin Mirabbaszadeh - avatar