Answer to Question #229957 in Python for Assignment

Question #229957
Write a python program that takes an input from the user and then prints numbers starting from 1 to the given input. The output should be in one line. Use while loop.

Example 1

Sample Input: 10

Sample Output: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

Example 2

Sample Input: 5

Sample Output: 1, 2, 3, 4, 5
1
Expert's answer
2021-08-26T08:17:26-0400
"""
Write a python program that takes an input from the user and then 
prints numbers starting from 1 to the given input. 
The output should be in one line. Use while loop.


Example 1


Sample Input: 10


Sample Output: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10


Example 2


Sample Input: 5


Sample Output: 1, 2, 3, 4, 5


"""
import math


while 1:
    N = int(input())
    if N > 0:
        break
    else:
        print("The number must be positive")


k = 0


while k < N:
    k = k + 1
    print(str(k) + ",", end = " ")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS