私の割り当てはここでstrとintの型を取得するのはなぜですか?
従業員の名前と給与を取得するプログラムを作成します。 連邦税および州税は、次の基準に基づいて計算します。 給与が100000を超える場合は、連邦税を20%で計算します。 連邦税を15%と計算します。州税を計算します。 5%従業員の給与。ネット 給与を計算するには、給与総額から連邦および州税を差し引きます。
マイコード:
employeename = input("Enter the employee's name:")
grosssalary = input("Enter the employee's gross salary: $")
if grosssalary > 100000:
federaltax = 0.20
else:
federaltax = 0.15
statetax = 0.05
netsalary = float(grosssalary) - float(grosssalary * federaltax) - float(grosssalary * statetax)
print (employeename,"'s net salary is $",netsalary)
出力:
Enter the employee's name:Ali
Enter the employee's gross salary: $1000
Traceback (most recent call last):
File "/home/ubuntu/workspace/Untitled4", line 3, in <module>
if grosssalary > 100000:
TypeError: unorderable types: str() > int()
Process exited with code: 1
まず、文字列をintに変換する必要があります。 –
これは確かに重複しています... –