修改前一项的程序,使其要求您输入 s 并进行计算,然后重复此操作,直到您输入负数 s

问题描述 投票:0回答:1

我不知道如何让我的代码重复,直到为 s 输入负值。

s=1000
S= 0
N= 0
while (S <= s):
  N+=1
  S+=N**3
print(f"The smallest sum of n**3 greater than {s} is {S}, where N = {N}")```
python google-colaboratory physics computation
1个回答
0
投票

Python While 循环
Python input() 函数

while True:
  s= int(input())
  if s < 0: break
  S= 0
  N= 0
  while (S <= s):
    N+=1
    S+=N**3
  print(f"The smallest sum of n**3 greater than {s} is {S}, where N = {N}")
© www.soinside.com 2019 - 2024. All rights reserved.