+ 1

[Solved]Ruby - Cheer Creator

This is the task: "Cheer Creator You are cheering on your favorite team. After each play, if your team got over 10 yards further down the field, you stand up and give your friend a high five. If they don't move forward by at least a yard you stay quiet and say 'shh', and if they move forward 10 yards or less, you say 'Ra!' for every yard that they moved forward in that play. Task Given the number of yards that your team moved forward, output either 'High Five' (for over 10), 'shh' (for <1), or a string that has a 'Ra!' for every yard that they gained. Input Format An integer value that represents the number of yards gained or lost by your team. Output Format A string of the appropriate cheer. Sample Input 3 Sample Output Ra!Ra!Ra!" And this is my code x = gets.to_i if x > 10 print "High Five" elsif x == 0 puts"shh" else x.times do print "Ra!" end end And i don't know why this doesyn't work. I pass 4/5 solutions but ia cant see 5 solutions and dunno what to do :/

28th Feb 2020, 11:55 PM
Ruby_Frog
Ruby_Frog - avatar
5 Réponses
+ 1
A-VIR 'shh' (for<1) but it's =0 in your code!
29th Feb 2020, 12:06 AM
Thống Nguyễn
Thống Nguyễn - avatar
+ 3
n=gets.chomp.to_i if n<1 puts "shh" elsif n>10 puts "High Five" else ca="" v=1 while v<=n do ca=ca+"Ra!" v=v+1 end puts ca end
29th Feb 2020, 12:12 AM
Cmurio
Cmurio - avatar
0
My code is: x = int(input()) if x < 1: print("shh") elif x > = 1 or x <10: print(x*("Ra!" elif x > 10: print("High five") I pass 4/5 solutions, I fail number three.
31st Jan 2023, 12:53 PM
Leonardo
Leonardo - avatar
0
yards = int(input()) if yards >= 10: print("High five") elif yards < 1: print("shh") elif yards > 1 and yards < 10: print("Ra!"*yards) elif yards == 0: print("stay quiet") else: print("unknown") 3/5 can't figure out what is wrong as well
15th Feb 2023, 6:16 PM
Paul Ngidi
Paul Ngidi - avatar
- 1
हम आपके कोड की क्वेरी तो solve नही कर सकते है पर हमने Python में code बनाया है, ये property work करता है, सारे 5/5 test cases satisfy हो रहे है I cannot solve your code query. But I coded it in Python, it works fine, all the 5 test cases are being satisfied. //My Code// yards = int(input()) if yards < 1: print('shh') if yards > 10: print('High Five') for i in range(yards): if yards <= 10 and yards>= 1: print('Ra!')
24th Sep 2022, 3:06 PM
Dhananjay Netam