2 回答
TA贡献1828条经验 获得超13个赞
所以这里有一个代码可以做你想要的。
现在说实话,它有效,但我不明白你为什么这样做。你做了一堆奇怪的计算,比如乘以和除以相同的数字......
IN = float(input("Enter IN: "))
N = float(input("Enter N: "))
NP = float(input("Enter NP: "))
# The part that interests you.
IN = 0.5 if IN == 0 else IN
N = 0.5 if N == 0 else N
NP = 0.5 if NP == 0 else NP
init = IN * 1/2
baselimiter = -N*1/2 + IN*1/2*NP*1/2 # Removed all the superfluous float() and parenthesis.
lset = init + baselimiter
limitconverto1 = (lset / init) * (init / lset) # That's just always 1. What is intended here?
infalatetoinput = (((init * float(IN))) / init ) # That's always IN. Same question?
limit = limitconverto1 * infalatetoinput # Equivalent to 1 x IN...
result = limit
print(result) # Your result is always IN...
TA贡献1793条经验 获得超6个赞
声明变量时可以使用单行:
IN = (float(input("...")) if float(input("...")) != 0 else .5)
单行是在声明变量时在一行而不是多行中的for循环或if语句(或两者)。它们只能用于变量的声明。我建议的单行是多行:
if float(input("...")) != 0:
IN = float(input("..."))
else:
IN = .5 #You don't need to say float(.5) since .5 is a float anyway.
我希望我以前的回答的这个编辑完全回答了你的问题,为了更多的澄清,我将在评论中提供
添加回答
举报