gpt4 book ai didi

python - 我如何根据用户提出的问题使用变量做公式

转载 作者:太空宇宙 更新时间:2023-11-04 04:14:13 25 4
gpt4 key购买 nike

我在第 5 行收到错误“TypeError: can't multiply sequence by non-int of type 'str'”,即“number = str(c(c*r)**x)”,这是一个制作增长计算器的尝试很弱。任何帮助都会很感激我是新手

import math
c = raw_input("what is the intial number?")
r = raw_input("What is the rate of growth?")
x = raw_input("How many years are taking place?")
int(c)
int(r)
int(x)
number = str(c(c*r)**x)
print (number)

最佳答案

您忘记重新分配变量:

import math
c = raw_input("what is the intial number?")
r = raw_input("What is the rate of growth?")
x = raw_input("How many years are taking place?")
c = int(c)
r = int(r)
x = int(x)
number = str(c*(c*r)**x)
print (number)

关于python - 我如何根据用户提出的问题使用变量做公式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55748216/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com