I got stuck in this problem. when the user enters the input number that is “N”. So I need to print the integers from N to 1. How to solve this problem in python? Explain in detail?
For suppose,
Test case:
input: 5
output: 5 4 3 2 1
Sign Up to our social questions and Answers Engine to ask questions, answer people's questions, and connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
deepika
To Write a program to print integers from N to 1, we use a loop in python.
let us store input value in a variable “n”, Now when user enters any number then that number gets stored into variable “n”.
We use for loop in range(n), we are using range(n) because we want a series of numbers.
To get number series from 1 to 5 we store this values in variable k.
now we can get the series that we required.
Required code is this:
n=int(input())
for i in range(n):
k=(n-i)
print(k)