首页 > 解决方案 > 尝试从 10 数到提供的输入值和 Python 中提供的列,但没有得到它。我基本上想要5个数字等

问题描述

counter = 10
numbers = int(input("Enter a number between 10 and 99: "))
column = int(input("How many columns would you like? "))
for num in range(10, numbers):
    for col in range(column):
        counter += 1
    print(num + 1, end= ' ')
print()

尝试从 10 数到提供的输入值和 Python 中提供的列,但没有得到它。我基本上想要顶部的 5 个数字,底部的 5 个等。

标签: pythonpython-3.xspyderjuniper

解决方案


counter = 10
numbers = int(input("Enter a number between 10 and 99: "))
column = int(input("How many columns would you like? "))
output_string = ""

col_counter = 0
while (counter <= numbers):
    output_string += str(counter)+" "
    counter += 1
    col_counter += 1
    if(col_counter == column):
       print(output_string)
       output_string=""
       col_counter = 0
print(output_string)

这应该做得很好


推荐阅读