我不能执行if语句来询问变量是否大于一个数字而小于另一个数字吗?

问题描述 投票:-2回答:1

我正在学习python,但我似乎不明白为什么我的代码是错误的。

  def rental_car_cost(days):
    rent = 40 * days
    if days >= 7:
      rent -=50
    elif days > 3 and days < 7: # is this allowed in Python?
      rent -=30
    return rent

我只想这样做3

我试图搜索if语句的语法,但无法在线找到答案。如果天数天数大于7,则租金=租金-50,如果天数大于3但小于7,则租金=租金-30。

    def rental_car_cost(days):
        rent = 40 * days
        if days >= 7:
            rent -=50
        elif days > 3 and days < 7: # is this allowed in Python?
            rent -=30
        return rent

错误表明未定义功能rental_car_cost ...

我正在学习python,但我似乎不明白为什么我的代码是错误的。 def rental_car_cost(days):租金= 40 *天,如果天数> = 7:租金-= 50 Elif天数> 3,天数<7:#...

python if-statement statements
1个回答
0
投票

这是您所寻找的最接近的:

© www.soinside.com 2019 - 2024. All rights reserved.