我不知道怎么把植物素的输出列为一个列表

2024-09-30 20:17:49 发布

您现在位置:Python中文网/ 问答频道 /正文

Write a Python program that requests the following three int values from the user:
a starting number
a ending number
an increment size
Display all of the numbers, starting with the first value, up to, but not including the second value, by incrementing by the third value. Separate values with commas. Do not include a comma after the last number. If the relationship between the starting and ending values does not make sense given the increment size, then do not display anything.

我创建的代码不会将它们显示为逗号。我得到的是:

def main():
  startingNum = int(input("Please enter a starting number:"))
  endingNum = int(input("Please enter an ending number:"))
  incrementSize = int(input("Please enter an increment size:"))
  lastValue = endingNum - incrementSize
  print(startingNum)
  if startingNum < lastValue:
    while startingNum < lastValue:
      value = startingNum + incrementSize
      startingNum = startingNum + incrementSize
      print(value)
  else:
    while startingNum > lastValue:
      value = startingNum + incrementSize
      startingNum = startingNum + incrementSize
      print(value)
main()

Tags: theannumberinputsizevalueendingnot