Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to make loops from smallest to largest number?

a = int(input("first number: "))
b = int(input("second number: "))
for x in range (a,b):
    print(x, end = ' ')

#I am making a program that would display a number from smallest to largest
#for example: the first number is 10 then the second number is 1 : and my expected result is 1,2,3,4,5,6,7,8,9. the program that I did is not working if a is lower than b . but is working if the a is higher than b

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If you want it to always go from min to max regardless of which one is min and which is max you could do something like this:

for x in range(min(a, b), max(a, b)):
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading