Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How to do this type of loop in python

–2 votes
asked Jan 18, 2019 by John Dolleslager (100 points)
I was wondering if this can be done in Python. This is from the OLD BASIC days:

input ("Input a number from 5 to 15");n

for x = 1 to n

print n, 10-x

next x

3 Answers

0 votes
answered Jan 19, 2019 by Roseline

n=int(input("Enter a number from 5 to 15: "))
for i in range(n+1):
    print(i)

output:

Enter a number from 5 to 15:6
0
1
2
3
4
5
6

0 votes
answered Jan 19, 2019 by anonymous

#   I have reformatted the pgm,please check out and let me know if any  changes

n=int(input("Enter a number from 5 to 15:"))
if n<=4:
    print("Sorry!!!!  You have entered value less than 5")
elif n>=5 and n<=15:
    for i in range(n+1):
        print(i)
else:
    print("Sorry!!  You have entered above 15")

commented Jan 22, 2019 by John Dolleslager (100 points)
I like this...THANKS!!!
0 votes
answered Jan 22, 2019 by benzzamakon
a = int(input("Enter first number: "))
if a < 5 or a >16:
    # TODO: write code...
    print("sorry,input 5 - 15 !!")
else:
    while a < 16 :
        print("a = ",a)
        b = 1
        a = a + b
        

ok ?
commented Jan 22, 2019 by John Dolleslager (100 points)
That is perfect...I like both ways. THANKS!!!
commented Jan 23, 2019 by นายเบ็นซ์รีวิว (250 points)
Nevermind ^_^
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...