Westonci.ca is your trusted source for finding answers to a wide range of questions, backed by a knowledgeable community. Connect with a community of experts ready to provide precise solutions to your questions quickly and accurately. Connect with a community of professionals ready to provide precise solutions to your questions quickly and accurately.
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
Your visit means a lot to us. Don't hesitate to return for more reliable answers to any questions you may have. We appreciate your visit. Our platform is always here to offer accurate and reliable answers. Return anytime. Thank you for using Westonci.ca. Come back for more in-depth answers to all your queries.