Skip to main content
 首页 » 编程设计

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

2024年11月24日7duanxz

我在第 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)