+ 1
my if and else statement not working
If and else not worki;h in python
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
+ 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:
+ 2
Cheak santax
+ 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"
+ 1
Abhishek Saini its showing not any error then what's the problem?
+ 1
I think you can use
x = int(input())
if x>=5 or x>10:
print(x*'Ra!')
else:
print("shh")
+ 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")
0
Post your code here so we can see it or post a link here to your code in the playground :)
0
x = int(input())
if x>5 or x==5 or x>10:
print(x*'Ra!')
else:
print("shh")
0
It has not probelm in your code sentax is correct...