+ 1

my if and else statement not working

If and else not worki;h in python

29th Nov 2020, 3:20 AM
Abhishek Saini
Abhishek Saini - avatar
10 Réponses
+ 3
You need to fix your code's if statement condition in first place. Expressions (x > 5) from 6 to ∞ and (x > 10) from 11 to ∞, so by using of expression (x > 5) you don't need the other one. That's the first thing You can also replace expression (x > 5 or x == 5) with (x ≥ 5). CAN'T TELL U ANYTHING ELSE BECAUSE YOUR CODE HAS NOT ERRORS. IF YOU DESCRIBE MORE YOUR PROBLEM, MAYBE I CAN HELP U
29th Nov 2020, 4:05 AM
Hacker-KR4636
Hacker-KR4636 - avatar
+ 3
Your code works fine. What is it supposed to do? If this is a Code Coach question, wasn't there a "High Five" involved? As Hacker-KR4636 pointed out, your second line is equivalent to if x >=5:
29th Nov 2020, 4:30 AM
David Ashton
David Ashton - avatar
+ 2
Cheak santax
29th Nov 2020, 3:23 AM
TANISHQ SAINI
TANISHQ SAINI - avatar
+ 2
Abhishek Saini looks like you're trying to solve the cheer creator code coach challenge. if less than 1 yard is gained output "shh" if 1 to 10 yards gained output "Ra!" once for each yard gained. if more than 10 yards gained output "High Five" You can use an if-elif-elif for each condition. x < 1 output "shh" x >= 1 and x < 11 (you could use x <= 10) output "Ra!" * x x > 10 output "High Five"
29th Nov 2020, 4:32 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Abhishek Saini its showing not any error then what's the problem?
30th Nov 2020, 7:50 AM
Sayyam Jain
Sayyam Jain - avatar
+ 1
I think you can use x = int(input()) if x>=5 or x>10: print(x*'Ra!') else: print("shh")
30th Nov 2020, 9:20 PM
‎مبارك حسن‎
+ 1
You need a high five output if its greater than 10. Your code will print Ra! even if the input is more than 10 yards. because of your statement x > 10. Try this: x = int(input()) if x > 5 and x < 10: print(x*'Ra!') elif x > 10: print('High Five!') else: print("shh")
1st Dec 2020, 12:58 AM
Dustin James Locey
Dustin James Locey - avatar
0
Post your code here so we can see it or post a link here to your code in the playground :)
29th Nov 2020, 3:25 AM
David Ashton
David Ashton - avatar
0
x = int(input()) if x>5 or x==5 or x>10: print(x*'Ra!') else: print("shh")
29th Nov 2020, 3:30 AM
Abhishek Saini
Abhishek Saini - avatar
0
It has not probelm in your code sentax is correct...
30th Nov 2020, 9:24 PM
‎مبارك حسن‎