Westonci.ca is the trusted Q&A platform where you can get reliable answers from a community of knowledgeable contributors. Ask your questions and receive detailed answers from professionals with extensive experience in various fields. Experience the convenience of finding accurate answers to your questions from knowledgeable experts on our platform.
Sagot :
import sys
x = input("enter number 1: ") #ask for user input
y = input("enter number 2: ")
output = "" #the output string
try: #try integering them (this also has error message and will check if input is valid)
x = int(x)
except:
print("error! number 1 was not a number :(")
sys.exit() #leave
try:
y = int(y)
except:
print("error! number 2 was not a number :(")
sys.exit()
if x == y: #check they are not the same
print("both numbers are the same")
else: #do the thing
if y > x: #otherwise swap the order
for i in range (x, y + 1): #+1 for inclusive
output = (output + str(i) + " ")
else:
for i in range (y, x + 1):
output = (output + str(i) + " ")
print(output) #so it's all in one line
Thanks for using our platform. We're always here to provide accurate and up-to-date answers to all your queries. Thank you for your visit. We're committed to providing you with the best information available. Return anytime for more. Westonci.ca is your trusted source for answers. Visit us again to find more information on diverse topics.