問題は次のとおりです。 事業者は、購入単位数と単価に基づいて割引を適用します。ユーザーにユニット数と単価を尋ね、合計価格、適用された割引、合計割引価格を計算して出力するアプリケーションを作成します。単位数が0以下の場合、または単位当りの価格が€0以下の場合は、適切なエラーメッセージを表示してください。このコードでの範囲と浮動小数点数のインターミキシング
ここに私のコードです:
units_brought = float(input("Enter the number of units brought "))
unit_price = float(input("Enter the unit price "))
total_price = units_brought * unit_price
discount_applied = float(0)
total_discounted_price = total_price - discount_applied
if units_brought in range(1, 49) and unit_price in range(0.01, 10) :
print("The total price is ",total_price,"\nThe discount applied is",discount_applied,"\nThe total discounted price is ",total_discounted_price)
if unit_price in range(10.01, 100) :
discount_applied = total_price * 0.05
print("The total price is ", total_price, "\nThe discount applied is", discount_applied,"\nThe total discounted price is ", total_discounted_price)
elif unit_price >= 100.1:
discount_applied= total_price * 0.08
print("The total price is ", total_price, "\nThe discount applied is", discount_applied,"\nThe total discounted price is ", total_discounted_price)
elif units_brought in range(50, 99) and unit_price in range(0.01, 10) :
discount_applied = total_price * 0.12
print("The total price is ", total_price, "\nThe discount applied is", discount_applied,
"\nThe total discounted price is ", total_discounted_price)
if unit_price in range(10.01, 100) :
discount_applied = total_price * 0.18
print("The total price is ", total_price, "\nThe discount applied is", discount_applied,
"\nThe total discounted price is ", total_discounted_price)
elif unit_price >= 100.01:
discount_applied = total_price * 0.22
print("The total price is ", total_price, "\nThe discount applied is", discount_applied,
"\nThe total discounted price is ", total_discounted_price)
elif units_brought >= 100 and unit_price in range(0.01, 10) :
discount_applied = total_price * 0.21
print("The total price is ", total_price, "\nThe discount applied is", discount_applied,
"\nThe total discounted price is ", total_discounted_price)
if unit_price in range(10.01, 100):
discount_applied = total_price * 0.32
print("The total price is ", total_price, "\nThe discount applied is", discount_applied,
"\nThe total discounted price is ", total_discounted_price)
elif unit_price >= 100.01:
discount_applied = total_price * 0.43
print("The total price is ", total_price, "\nThe discount applied is", discount_applied,
"\nThe total discounted price is ", total_discounted_price)
elif units_brought <= 0:
print("The number of units brought can't be zero or less")
elif unit_price <= 0:
print("The unit price can't be zero or less")
これは、それが実行されるときに何が起こるかです:
Enter the number of units brought 5
Enter the unit price 4
Traceback (most recent call last):
File "C:/Users/User/Documents/My code/business_price_&_discounts.py", line 19, in <module>
if units_brought in range(1, 49) and unit_price in range(0.01, 10) :
TypeError: 'float' object cannot be interpreted as an integer
Process finished with exit code 1
をので、問題はながら山車を持つことができないif文で範囲機能のようです同時に小数点を必要とする私の価値、私の質問は、ここに範囲関数の代替ですか?フォームで