ai didi

python - pylint "invalid syntax"(语法错误)来自 '*='

转载 作者:太空宇宙 更新时间:2023-11-03 15:15:17 24 4
gpt4 key购买 nike

我从 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

最佳答案

使用 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 + increase
num_days += 1
return num_days

关于python - pylint "invalid syntax"(语法错误)来自 '*=',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43932829/

24 4 0
文章推荐: python - 使用 Python Boto 和 Amazon Glacier concurrent.ConcurrentUploader 保证数据完整性?
文章推荐: javax.net.ssl.SSLPeerUnverifiedException : peer not authenticated error
文章推荐: python - 根据 csv 文件创建的列表将文件从一个目录复制到另一个目录
文章推荐: python - 使用 selenium (Python) 轮换服务器 IP
太空宇宙
个人简介

我是一名优秀的程序员,十分优秀!

滴滴打车优惠券免费领取
滴滴打车优惠券
全站热门文章
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com