python - Python输入函数复制
问题描述
为什么我的输入被问了两次是有原因的吗?我需要使用三个单独的函数来使用用户输入来计算公式。
def values():
initInv=input("Enter initial investment ")
rate=input("Enter the interest rate in the form of a decimal ")
freq=input("Enter the frequency that the interest is paid out per year ")
years=input("Enter the number of years the interest is compounded for ")
return initInv, rate, freq, years
w, x, y, z=values()
def typecast():
invest=int(w)
RATE=float(x)
FREQ=int(y)
time=int(z)
return invest, RATE, FREQ, time
first, second, third, fourth=typecast()
def formula():
P=first
r=second
n=third
t=fourth
A=(P*(1+(r/n))**(n*t))
return A
values()
typecast()
formula()
解决方案
你打values
了两次电话。定义后w, x, y, z=values()
一次:然后在最后:values()
编辑:与typecast
. 你也叫它两次。
这是删除重复项的代码。
def values():
initInv=input("Enter initial investment ")
rate=input("Enter the interest rate in the form of a decimal ")
freq=input("Enter the frequency that the interest is paid out per year ")
years=input("Enter the number of years the interest is compounded for ")
return initInv, rate, freq, years
def typecast():
invest=int(w)
RATE=float(x)
FREQ=int(y)
time=int(z)
return invest, RATE, FREQ, time
def formula():
P=first
r=second
n=third
t=fourth
A=(P*(1+(r/n))**(n*t))
return A
w, x, y, z=values()
first, second, third, fourth=typecast()
A = formula()
推荐阅读
- sql-server - id 从 1 , 2 跳到 1002, 2005, 2006
- java - 如何调整 JPanel 的高度?
- ios - Xcode12:如何停止在我的预览中显示自定义按钮类名
- html - 为什么有时 name="btnI" 不像正确的 google 的“我很幸运”按钮那样工作?
- grep - Grep 多个单词的行和行尾,如果匹配则替换行尾
- apache-superset - SuperSet 将计算字段添加到现有数据集
- c++ - AVX(2) 收集指令如何实际计算提取地址?
- c++ - 当我们使用 & 运算符时,Scanf 会发生什么?
- java - 在java项目中面临异常“无法解析类型”
- c# - 为什么我的 .net core xunit 测试找不到我的 appsettings.json?