Premier utilisateur de python ici. J'essaie d'utiliser une boucle while pour configurer un type d'outil de recherche pour les cours scolaires. J'obtiendrai les invites pour insérer le sujet et le CatalogNbr ; mais au lieu d'imprimer le nom du cours (par exemple "Introduction à la recherche" du premier bloc) comme j'en ai besoin, il revient immédiatement à demander à nouveau des entrées pour le sujet et le CatalogNbr.
D'après ce que j'ai recherché jusqu'à présent, je dois inclure des instructions break et continue entre les boucles, mais chaque fois que j'essaie d'inclure celles-ci, j'obtiens des erreurs de syntaxe.
Toute aide sur la façon d'accomplir cela sera grandement appréciée
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!")
Parce que python se soucie de l'indentation, votre while
boucle ne boucle que sur les deux premières lignes, car le reste du programme est censé s'exécuter une fois la boucle while terminée. L'indentation de tout le code du premier if
et des suivants devrait résoudre votre problème.
Cet article est collecté sur Internet, veuillez indiquer la source lors de la réimpression.
En cas d'infraction, veuillez [email protected] Supprimer.
laisse moi dire quelques mots