At Westonci.ca, we connect you with experts who provide detailed answers to your most pressing questions. Start exploring now! Join our Q&A platform to connect with experts dedicated to providing precise answers to your questions in different areas. Get quick and reliable solutions to your questions from a community of experienced 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
We hope this information was helpful. Feel free to return anytime for more answers to your questions and concerns. Thank you for your visit. We're committed to providing you with the best information available. Return anytime for more. Discover more at Westonci.ca. Return for the latest expert answers and updates on various topics.