首页 > 解决方案 > 获取名为 region_name 的第三个输入,它是一个字符串。将 region_list 中包含的适当字符串附加到您的打印语句中

问题描述

问题是:

上面的assessRent() 函数非常方便。唯一的限制是它会产生通用响应。修改代码以执行以下操作:

1)获取第三个输入,称为 region_name,它是一个字符串

2) 将 region_list 中包含的适当字符串附加到您的打印语句中,以给出与上下文相关的响应

def assessRent(region_list, threshold, region_name):
  i = 0
  while i < len(region_list): 

    if region_list[i] < region_name: 

        if i == 0: # modify the string response below

            print("A Bachelor apartment in this region costs " + int(region_list[i]) + " on average, which is affordable")

        else: # modify the string response below
            print("A " + str(i) + " bedroom apartment in this region costs " + int(region_list[i]) + " on average, which is affordable")

i += 1

错误信息:

TypeError:“int”和“str”的实例之间不支持“<”

标签: pythonstringintinstancetypeerror

解决方案


推荐阅读