2 回答

TA貢獻1828條經(jīng)驗 獲得超13個贊
所以這里有一個代碼可以做你想要的。
現(xiàn)在說實話,它有效,但我不明白你為什么這樣做。你做了一堆奇怪的計算,比如乘以和除以相同的數(shù)字......
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條經(jīng)驗 獲得超6個贊
聲明變量時可以使用單行:
IN = (float(input("...")) if float(input("...")) != 0 else .5)
單行是在聲明變量時在一行而不是多行中的for循環(huán)或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.
我希望我以前的回答的這個編輯完全回答了你的問題,為了更多的澄清,我將在評論中提供
添加回答
舉報