擅长:python、mysql、java
<p>虽然@FredMan是对的,但我觉得你真的可以整理你的循环。我不是Python人,但我想到的是:</p>
<pre><code>def main():
keep_going = '';
while keep_going != 'n':
input_1 = int(input('Please enter a value: '))
input_2 = int(input('Please enter a second value: '))
input_3 = int(input('Please enter a third value: '))
input_4 = int(input('Please enter a fourth value: '))
print('The total amount is: ', end='')
# In your example, you sum input_1 four times
# \n at the end adds a newline
print(all_inputs(input_1,input_2,input_3,input_4), end="\n")
keep_going = input('Keep going? y/n: ')
def all_inputs(first,second,third,fourth):
sum = first + second + third + fourth
return(sum)
main()
</code></pre>
<p>有很多其他的方法来清理这个问题,但我觉得这是一个简单的修复方法,可以让你记住你想要的风格:)</p>
<p>编辑:这里有另一种方法</p>
^{pr2}$