from IPython.display import clear_output
def inchtofeet(inches):
todosinches = []
for i in inches:
newinfeets = (i / 12.00)
todosinches.append(newinfeets)
return todosinches
def cubicfeet(feets):
final = 1
for i in feets:
final = final * i
return final * 11.00
def sumarcurrent(currents):
suma = 0
for i in currents:
suma = suma + i
return (str(suma) +'$')
start = True
listainput = []
inputcount = 0
solosuma = []
while start:
inputinch = raw_input()
print listainput
if inputcount == 2:
listadeinches = inchtofeet(listainput)
print cubicfeet(listadeinches),'$'
inputcount = 0
listainput = []
elif inputinch == 'stop':
break
elif inputinch == 'suma':
print sumarcurrent(solosuma)
solosuma = []
else:
listainput.append(int(inputinch))
inputcount +=1
continue
我的代码应该得到3个输入,然后进行数学运算,但是第一个输入没有在列表中保存,所以在第一次输入后列表仍然是空的,其他2个正在保存在列表中
答案 0 :(得分:0)
请检查一下是否有效。由于最新输入未添加到list-listainput,因此您将遇到此问题。
from IPython.display import clear_output
def inchtofeet(inches):
todosinches = []
for i in inches:
newinfeets = (i / 12.00)
todosinches.append(newinfeets)
print(todosinches)
return todosinches
def cubicfeet(feets):
final = 1
for i in feets:
final = final * i
return final * 11.00
def sumarcurrent(currents):
suma = 0
for i in currents:
suma = suma + i
return (str(suma) +'$')
start = True
listainput = []
inputcount = 0
solosuma = []
while start:
inputinch = int(input("Hi give the inch:"))
if inputcount == 2:
listainput.append(inputinch)
listadeinches = inchtofeet(listainput)
print(cubicfeet(listadeinches),'$')
inputcount = 0
listainput = []
elif inputinch == 9999:
break
elif inputinch == 9998:
print(sumarcurrent(solosuma))
solosuma = []
else:
listainput.append(inputinch)
inputcount +=1
print(listainput)
continue
我确实在运行并且所有输入条目都已存储并用于计算。