# What is wrong with this code?

colours = ("Red", "Orange", "Yellow", "Blue", "Purple")
input ("What Element would you like to print? (Number): ")
if:
input = 0
print (colours)
else:
elif:
input = 1
print (colours)
else:
elif:
input = 2
print (colours)
else:
elif:
input = 3
print (colours)
else:
elif:
input = 4
print (colours)
else:
elif:
input =(> 4)
print ("Sorry, error.")

answered May 16 by (500 points)
selected May 16 by

i thing every thing is right
commented May 18 by (100 points)
an equivalent code.

colours = ("Red", "Orange", "Yellow", "Blue", "Purple")
num = float(input("Enter a number: "))
if num == 0:
print (colours)
elif num == 1:
print (colours)
elif num == 2:
print (colours)
elif num == 3:
print (colours)
elif num == 4:
print (colours)
else:
print ("Sorry, error.")
answered May 18 by (780 points)

try it this way:

colours = ("Red", "Orange", "Yellow", "Blue", "Purple")
input=int(input("What Element would you like to print? (Number): "))
if input == 0:
print (colours)
elif input == 1:
print (colours)
elif input == 2:
print (colours)
elif input == 3:
print (colours)
elif input == 4:
print (colours)
elif input >= 4:
print ("Sorry, error.")

+1 vote
answered May 22 by (210 points)
you have to use (else if) statement  instead of (if) statement
answered May 22 by (210 points)

try it this way:

colours = ("Red", "Orange", "Yellow", "Blue", "Purple")
input=int(input("What Element would you like to print? (Number): "))
if input == 0:
print (colours)
elif input == 1:
print (colours)
elif input == 2:
print (colours)
elif input == 3:
print (colours)
elif input == 4:
print (colours)
elif input >= 4:
print ("Sorry, error.")

commented May 22 by (170 points)
Wow, thanks!
answered May 22 by (220 points)
Use nested if statements (if else if) in your code that will help make it easier to read and condense your code further to help you find more errors while debugging
answered May 23 by (180 points)

you need to write elif rather than else because,if you write else, it stops there and doesn't check the next condition because it's the last condition so you should use elif in order to continue to the next condition

answered May 23 by (270 points)
colours = ("Red", "Orange", "Yellow", "Blue", "Purple")
input=int(input("What Element would you like to print? (Number): "))
if input == 0:
print(colours)
elif input==1:
print (colours)
elif input==2:
print (colours)
elif input==3:
print (colours)
elif input==4:
print (colours)
else:
print ("Sorry, error.")

https://onlinegdb.com/SkVrCjUiL