First time python user here. I am trying to use a while loop to set up a type of search tool for school courses. I will get the prompts to insert the Subject and CatalogNbr; but instead of printing the course name (e.g. "Introduction to Research" from the first block) like I need, it immediately loops back to requesting inputs for the Subject and CatalogNbr again.
From what I have researched so far, I need to include break and continue statements between the loops, but everytime I try to include those I get syntax errors.
Any help on how to accomplish this will be greatly appreciated
Query = 'Y'
while Query == 'Y':
Subject = input("Enter the Subject: \n> ")
CatalogNbr= input("Enter the CatalogNbr: \n> ")
if Subject == 'LIBS' and CatalogNbr == '150':
print(f"The title of {Subject,CatalogNbr} is Introduction to Research")
Query = input("\nWould you like to search for another title? (Y or N)\n> ")
elif Subject == 'SDEV' and CatalogNbr == '400':
print(f"The title of {Subject,CatalogNbr} is Secure Programming in the Cloud")
Query = input("\nWould you like to search for another title? (Y or N)\n> ")
elif Subject == 'PHIL' and CatalogNbr == '348':
print(f"The title of {Subject,CatalogNbr} is Religions of the East")
Query = input("\nWould you like to search for another title? (Y or N)\n> ")
elif Subject == 'BEHS' and CatalogNbr == '320':
print(f"The title of {Subject,CatalogNbr} is Disability Studies")
Query = input("\nWould you like to search for another title? (Y or N)\n> ")
elif Subject == 'PSYC' and CatalogNbr == '354':
print(f"The title of {Subject,CatalogNbr} is Cross-Cultural Psychology")
Query = input("\nWould you like to search for another title? (Y or N)\n> ")
elif Subject == 'SPCH' and CatalogNbr == '482':
print(f"The title of {Subject,CatalogNbr} is Intercultural Communication")
Query = input("\nWould you like to search for another title? (Y or N)\n> ")
elif Subject == 'WMST' and CatalogNbr == '200':
print(f"The title of {Subject,CatalogNbr} is Introduction to Womens Studies Women and Society")
Query = input("\nWould you like to search for another title? (Y or N)\n> ")
elif Subject == 'HYST' and CatalogNbr == '482':
print(f"The title of {Subject,CatalogNbr}is History of Japan to 1800")
Query = input("\nWould you like to search for another title? (Y or N)\n> ")
elif Subject == 'ASDT' and CatalogNbr == '370':
print(f"The title of {Subject,CatalogNbr} is Interpreting Contemporary China")
Query = input("\nWould you like to search for another title? (Y or N)\n> ")
elif Subject == 'JAPN' and CatalogNbr == '333':
print(f"The title of {Subject,CatalogNbr} is DJapanese Society and Culture")
Query = input("\nWould you like to search for another title? (Y or N)\n> ")
else:
print(f"I'm sorry {Subject,CatalogNbr} is not an avalible option.")
if Query == 'N':
print("Thank you for using the Catalog Search!")
Because python cares about indentation, your while
loop only loops over the first two lines, as the rest of the program is seen as supposed to execute after the while loop finishes. Indenting all the code from the first if
and forwards should fix your problem.