0
Can someone help me with my python code
Hello guys, I'm a beginner in python and student, I'm having a hard time analyzing this code. why the if statement is invalid/ error. Can someone help me? I really much appreciate it! wavelength = int(input("Enter wavelength : ")) if(wavelength>=380 && wavelength<450): print("Color: Violet") elif(wavelength>=450 && wavelength<495): print("Color: Blue") elif(wavelength>=495 && wavelength<570): print("Color: Green") elif(wavelength>=570 && wavelength<590): print("Color: Yellow") elif(wavelength>=590 && wavelength<620): print("Color: Orange") elif(wavelength>=620 && wavelength<750): print("Color: Red") else: print("Wavelength entered is outside the visible spectrum")
11 Answers
+ 4
krstnn
you have 2 mistakes
1.... use "and" instead of &&
2.... check indentation of print statement
see this
https://code.sololearn.com/c5DkqNE5bKS5/?ref=app
+ 6
krstnn
And then you could actually make use of combined inequality to make the code more concise…
For example,
wavelength >= 620 and wavelength < 750
Can be brought down to
619 < wavelength < 750
Or
620 <= wavelength < 750
+ 4
thank you so much!!
+ 1
I think put or instead of and once try it
+ 1
how? i still didn't know, it says syntax error.
+ 1
check this
+ 1
I'll try it thank tou
+ 1
https://code.sololearn.com/cJnphyx94ivu/?ref=app
Once see this
+ 1
In my opinion this is right
0
Would you please show you code
krstnn