+ 1

Python for beginners 24.2

I don’t know what’s wrong with my code? purity = float(input()) if purity >= 99.9: print("24k") else: if purity >= 91.7 and purity < 99.9: print("22k") else: if purity >= 83.3 and purity < 91.7: print("20k") else: if purity >= 75.0 and purity <83.3: print("18k")

28th Apr 2021, 1:25 AM
Chen Lyneing
Chen Lyneing - avatar
2 odpowiedzi
+ 1
If this code was placed in a code bit and then you run you get errors our output. Like that you will understand what happened wrong..
28th Apr 2021, 1:30 AM
Steve Sajeev
Steve Sajeev - avatar
0
Chen Lyneing You can't have an "else" block without an "if". The rule is, either if block followed by else block (or) just if block alone... In case of multiple conditions you can go with "if-elif-[else] " block which is similar to "if-else if-[else] " in C programming language..
28th Apr 2021, 2:13 AM
sarada lakshmi
sarada lakshmi - avatar