# 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[0])
else:
elif:
input = 1
print (colours[1])
else:
elif:
input = 2
print (colours[2])
else:
elif:
input = 3
print (colours[3])
else:
elif:
input = 4
print (colours[4])
else:
elif:
input =(> 4)
print ("Sorry, error.")

answered May 16, 2020 by (540 points)
selected May 16, 2020 by Aeshan Dave

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

colours = ("Red", "Orange", "Yellow", "Blue", "Purple")
num = float(input("Enter a number: "))
if num == 0:
print (colours[0])
elif num == 1:
print (colours[1])
elif num == 2:
print (colours[2])
elif num == 3:
print (colours[3])
elif num == 4:
print (colours[4])
else:
print ("Sorry, error.")
commented Jun 7, 2020 by (190 points)
All other answers are totally correct, just adding this assuming you have knowledge about errors which can arise.
colors = ("Red", "Orange", "Yellow", "Blue", "Purple")
try:
print(colors[int(input("What element would you like to print? (Number): "))])
except IndexError:
print("Out of Index")
commented Jan 28, 2021 by (2,920 points)
this one works
answered May 18, 2020 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[0])
elif input == 1:
print (colours[1])
elif input == 2:
print (colours[2])
elif input == 3:
print (colours[3])
elif input == 4:
print (colours[4])
elif input >= 4:
print ("Sorry, error.")

answered May 22, 2020 by (230 points) 1 flag
you have to use (else if) statement  instead of (if) statement
answered May 22, 2020 by (230 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[0])
elif input == 1:
print (colours[1])
elif input == 2:
print (colours[2])
elif input == 3:
print (colours[3])
elif input == 4:
print (colours[4])
elif input >= 4:
print ("Sorry, error.")

commented May 22, 2020 by (180 points)
Wow, thanks!
answered May 22, 2020 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, 2020 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, 2020 by (290 points)
colours = ("Red", "Orange", "Yellow", "Blue", "Purple")
input=int(input("What Element would you like to print? (Number): "))
if input == 0:
print(colours[0])
elif input==1:
print (colours[1])
elif input==2:
print (colours[2])
elif input==3:
print (colours[3])
elif input==4:
print (colours[4])
else:
print ("Sorry, error.")

https://onlinegdb.com/SkVrCjUiL