+ 1

Why this code is giving me error

I am new to python so please help https://code.sololearn.com/cBZSYtuIV0xN/?ref=app

5th Apr 2023, 3:05 PM
Aditya Verma
Aditya Verma - avatar
2 Answers
+ 4
# It’s indentation problem. You can try something like this: cls = input("Enter your class: ") s = input("Enter your stream: ") if cls == "11" or cls == "12": if s == "S" or s == "s": print("Your allotted section is 'A'.") elif s == "C" or "c": print("Your allotted section is'B'.") elif s == "H" or s == "h": print("Your allotted section is 'C'.") else: print("You have entered a wrong stream.") # And instead of s == "C" or "c" # you can try: s in "cC" # or: s.lower() == "c" # or: s.lower() in "c" # etc: It will do the code more easy to read (in my opinion).
5th Apr 2023, 3:29 PM
Per Bratthammar
Per Bratthammar - avatar
+ 4
There is no error in code. But have logic mistakes due to indentations.. And for comparing "c" missing == , use s=="c" Your elif condition belong to first cls if condition. But those should be indented to inside if condition for stream. Corrected code, hope it helps to identify your mistakes.. : # this is a program to accept the class and stream of a student and allot the section. # if you want science then choose S # if you want Finance then choose C # if you want Humanities then choose H cls=input("Enter your class:") s=input("Enter your stream:") if cls=="11" or cls=="12": if s=="S" or s=="s": print ("your allotted section is 'A'.") elif s=="C" or s=="c": print("Your allotted section is'B'.") elif s=="H" or s=="h": print("Your allotted section is'C'.") else: print("You have entered a wrong stream.") else: print("wrong input for class") #for your understandings.. #run code with different inputs and observe output.
5th Apr 2023, 3:25 PM
Jayakrishna 🇼🇳