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")

7th Apr 2022, 2:38 AM
krstnn
krstnn - avatar
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
7th Apr 2022, 3:03 AM
NonStop CODING
NonStop CODING - avatar
+ 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
7th Apr 2022, 7:57 AM
James Samuel
James Samuel - avatar
+ 4
thank you so much!!
7th Apr 2022, 3:07 AM
krstnn
krstnn - avatar
+ 1
I think put or instead of and once try it
7th Apr 2022, 2:58 AM
UNKNOWN
+ 1
how? i still didn't know, it says syntax error.
7th Apr 2022, 3:01 AM
krstnn
krstnn - avatar
+ 1
check this
7th Apr 2022, 3:03 AM
krstnn
krstnn - avatar
+ 1
I'll try it thank tou
7th Apr 2022, 3:04 AM
krstnn
krstnn - avatar
7th Apr 2022, 3:05 AM
UNKNOWN
+ 1
In my opinion this is right
7th Apr 2022, 5:20 AM
Sardor Kuvondikov
Sardor Kuvondikov - avatar
0
Would you please show you code krstnn
7th Apr 2022, 3:02 AM
UNKNOWN