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

标签 python python-2.7

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

相关文章:

python - pd.cut 非均匀 bin 间隔

python - 快速映射/修改大量 Python 字典中的值?

python - 为什么文件处理程序不能在 python 中多次使用?

python - 如果找不到 item 中的字母之一,我该如何循环它来执行 driver.refresh() 并重试?

python - Python3 中的 Heapq 不适用于元组,因为它不会按预期顺序弹出

python - 在 numba nopython 函数中计算阶乘的最快方法

python - 如何在 youtube API 中将我的视频上传到其他 channel

python - 如何以干净整洁的方式打印数据

php - 是否存在一个不错的 python wsgi 来本地管理 MYSQL 数据库?或者我必须自己编码一个?

python - PyTorch - 运行时错误 : Assertion 'cur_target >= 0 && cur_target < n_classes' failed