所以我从pylint得到一个语法错误,我相信使用' ='时会出现错误,我的原始代码只使用'',但这给了我错误的答案的问题。我在' ='上尝试了多种变体,但它们都不起作用。 Pylint说错误在第8行,尽管我认为是第7行的错误。如果我只有''它通过了pylint检查。
有什么建议吗?
def num_doublings(initial_population, final_population):
"""prints how many days it takes for a population to reach a certain
number, if the population is doubling daily"""
current_pop = initial_population
num_days = 0
while current_pop < final_population:
increase = current_pop *= 2
current_pop = current_pop + increase
num_days += 1
return num_days
答案 0 :(得分:0)
使用python
无法做到这一点increase = current_pop *= 2
这是另一种选择
def num_doublings(initial_population, final_population):
"""prints how many days it takes for a population to reach a certain
number, if the population is doubling daily"""
current_pop = initial_population
num_days = 0
while current_pop < final_population:
current_pop *= 2
increase = current_pop
current_pop = current_pop +
num_days += 1
return num_days