0
print ("Welcome teaacher")  
while True:
   Class = input("Which class (1, 2 or 3) would you like to look at?")
    if Class.lower() not in ('1', '2', '3'):
    print("Not an appropriate choice.")
else:
    break
while True:
    print("Which method would you like to view by?")
    Method = input("Type '1' for average, '2' for highest score or '3' for alphabetical")
    if Class.lower() not in ('1', '2', '3'):
        print("Not an appropriate choice.")
else:
    break
if Method == 1:
    print("You have chosen Class" +Class+ " average")
if Method == 2:
    print("You have chosen Class" +Class+ " highest score")
if Method == 3:
    print("You have chosen Class" +Class+ " alphabetical")

I'm trying to get the code to tell me what I've selected but it doesn't recognise the if statements at the end and doesn't print anything at all.

Any help would be great thanks :)

1 Answers1

2

Proper indentation is a fundamental part of Python. The way you've written your question, the else statement is applying to the while loops (which is a completely valid thing) and not to the if statements within the loops. Also, the final if statement should use elif, which is the Python abbreviation for else if.

Here's what it should look like:

print ("Welcome teacher")  
while True:
    Class = input("Which class (1, 2 or 3) would you like to look at?")
    if Class.lower() not in ('1', '2', '3'):
        print("Not an appropriate choice.")
    else:
        break

while True:
    print("Which method would you like to view by?")
    Method = input("Type '1' for average, '2' for highest score or '3' for alphabetical")
    if Class.lower() not in ('1', '2', '3'):
        print("Not an appropriate choice.")
    else:
        break

if Method == '1':
    print("You have chosen Class" + Class + " average")
elif Method == '2':
    print("You have chosen Class" + Class + " highest score")
elif Method == '3':
    print("You have chosen Class" + Class + " alphabetical")
Akshat Mahajan
  • 9,543
  • 4
  • 35
  • 44
tryexceptpass
  • 529
  • 5
  • 14