+ 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")
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.
+ 2
if distance >= 1 and distance <= 10
+ 1
Oohhh man thank you so much, it's really opening my mind 😳 so that's the logic. Thanks for the enlightenment
0
Thanks for the help, but can you explain why using "and" work but not "or"?
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



