0

Python if else

Please help me check this code I don’t know the problem it’s given me error total = input("How many do you want ?") if(total <= 0): print ("Input a number greater than 0"); else: charge = 1200 if(total >= 10) : charge = 1000; if(total >= 100) : charge = 700; print("Total charge = " + charge * total ) https://code.sololearn.com/c97scns93IKS/?ref=app

9th Jan 2023, 6:16 PM
Ahmad Mansir
3 ответов
+ 1
Here is fixed one : total = int(input("How many do you want ?")) if total <= 0: print("Input a number greater than 0") else: charge = 1200 if total >= 10: charge = 1000 if total >= 100: charge = 700 print("Total charge = " + str(charge * total))
9th Jan 2023, 7:27 PM
Aditya Dixit
0
There are a couple of issues with this code: 1. input() returns a string, so when you compare it to a number using <=, you are comparing a string to a number. This will cause a type error. To fix this, you can convert the input to an integer using int(): total = int(input("How many do you want ?")) 2. When you concatenate a string and a number using +, Python will also raise a type error. To fix this, you can convert the charge to a string before concatenating it: print("Total charge = " + str(charge * total))
9th Jan 2023, 7:27 PM
Aditya Dixit