If and else not worki;h in python
11/29/2020 3:20:03 AM
Abhishek Saini10 Answers
New AnswerYou 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
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:
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"
I think you can use x = int(input()) if x>=5 or x>10: print(x*'Ra!') else: print("shh")
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")
Post your code here so we can see it or post a link here to your code in the playground :)
Learn Playing. Play Learning
SoloLearn Inc.
4 Embarcadero Center, Suite 1455Send us a message