我是编码的新手,我不断得到:如果rentalCode ==' D'和averageDayMiles< 100:TypeError:unorderable类型:str()< INT()

时间:2017-11-22 00:02:14

标签: python

4)找出totalMiles:

提示 - > totalMiles = int(odoEnd) - int(odoStart)

提示 - > averageDayMiles = totalMiles / daysRented

totalMiles =?

    totalMiles = 2222 - 1234

    averageDayMiles = input(totalMiles/daysRented)

    if rentalCode == 'D' and averageDayMiles < 100:

        mileCharge = 0

   if averageDayMiles > 100 and rentalCode == 'D':

       extraMiles = averageDayMiles - 100

       mileCharge = extraMiles * 0.25*daysRented

   elif rentalCode == 'W':

      weeksRented = rentalPeriod

      averageMiles = totalMiles/weeksRented

   if averageMiles > 900:

     mileCharge = weeksRented * 100.00

  else:

    mileCharge = 0

我很难弄清楚如何对上面的代码进行编码,这样我就不会收到以下错误:TypeError:unorderable types:str()&lt; INT()

如果有人有建议或者可以引导我指向链接或阅读的方向,这将有助于我更好地理解,我会非常感激。提前谢谢

1 个答案:

答案 0 :(得分:0)

这里的问题是python 3中的输入总是返回一个字符串,而不是一个整数。因此,当你写averageDayMiles&gt; 100,你正在比较一个单词和一个数字。您需要编写以下内容:

if int(averageDayMiles) > 100 and rentalCode == 'D':

int(averageDayMiles)将您的字符串转换为int。