+ 1

Hello, I try to code cheer creator but cannot past the test case 3, can you help me to find the problem?

This is my code: distance = int(input()) if distance < 1: print("shh") if distance >= 1 or distance <= 10: print("Ra!" * distance) if distance > 10: print("High Five")

27th Jun 2022, 9:43 AM
Arka Style
Arka Style - avatar
5 Antwoorden
+ 2
"and" means we want distance to be >= 1 and <= 10 at the same time. "or" is is enough if one of the conditions is true. Suppose distance = 12 and we use "or". Then it would print Ra!*distance as 12 is >= 1 and it doesn't matter that 12 is not <= 10, as the first part would be true and that suffices.
27th Jun 2022, 10:10 AM
Lisa
Lisa - avatar
+ 2
if distance >= 1 and distance <= 10
27th Jun 2022, 9:47 AM
Lisa
Lisa - avatar
+ 1
Oohhh man thank you so much, it's really opening my mind 😳 so that's the logic. Thanks for the enlightenment
27th Jun 2022, 10:45 AM
Arka Style
Arka Style - avatar
0
Thanks for the help, but can you explain why using "and" work but not "or"?
27th Jun 2022, 9:49 AM
Arka Style
Arka Style - avatar
0
But this still gave an error at case 3 import java.util.Scanner; public class CheerCreator{ public static void main(String[] args){ //creating scanner obj as input Scanner input = new Scanner(System.in); //accept sample int cheer = input.nextInt(); if (cheer>10){ System.out.println("High five"); }//first if else if (cheer<1){ System.out.println("shh"); }//second if else{ System.out.print("Ra!".repeat(cheer)); }//else }//main }//CheerCreator class
6th Nov 2025, 9:20 PM
Ekwere Noble
Ekwere Noble - avatar