Ich mache ein Stück Code für eine Schule mit 7-10 Jahre alten Studenten, die ihre grundlegenden arithmetischen Fähigkeiten testen werden. Das Programm ist voll funktionsfähig und sollte es dem Lehrer ermöglichen, die Noten später in Textdateien zu sehen. Derzeit sind es 556 Zeilen. Ich habe es so weit wie möglich verkürzt, aber ich kann nicht scheinen, um dieses ein Stück Code zu arbeiten:Während Schleife in Funktion nicht funktioniert (Python 3.5.0)
def Repeat(repeat_q, option_right, t_class_right):
repeat_q = input("\n\nWould you like to see any other class details? ")
if repeat_q == "Yes" or repeat_q == "yes":
option_right = False
t_class_right = False
repeat_question = True
repeat_q = " "
elif repeat_q == "No" or repeat_q == "no":
print("Okay...")
repeat = False
T_Exit()
else:
print("Please only write 'yes' or 'no'")
return repeat_question
Diese Funktion später wie folgt aufgerufen wird:
elif test == 2:
OP_2(list_counter, repeat_question)
while repeat_question != True:
Repeat(repeat_q, option_right, t_class_right)
alle es tut, So wiederholen Sie die Variable 'repeat_q'. Ich habe versucht, nachdem er den Wert der Variablen ändert aber nichts scheint work.i kann es an die Arbeit, wenn ich es aus der Funktion übernehmen, wie folgt aus:
elif test == 3:
OP_3(list_counter, repeat_question)
while repeat_question != True:
repeat_q = input("\n\nWould you like to see any other class details? ")
if repeat_q == "Yes" or repeat_q == "yes":
option_right = False
t_class_right = False
repeat_question = True
elif repeat_q == "No" or repeat_q == "no":
print("Okay...")
repeat = False
T_Exit()
else:
print("Please only write 'yes' or 'no'")
Dies ist, was mit dem Code passiert:
Hello and welcome to my quiz.
Please write your name: teacher
Write the number of the class you would like to see (1, 2 or 3): 1
Opening Class 1
_________________________________________
| |
| 1) Alphabetical with highest score |
| 2) Highest score, highest to lowest |
| 3) Average score, highest to lowest |
|_________________________________________|
Choose one of the options above (1, 2 or 3): 2
Sorting by highest score, from highest to lowest
['Lol: 10', 'Zaid: 9', 'Abdul: 8', 'Hello: 5', 'Bruno: 5']
Would you like to see any other class details? yes
Would you like to see any other class details? yes
Would you like to see any other class details? yes
Would you like to see any other class details? yes
Would you like to see any other class details? no
Okay...
You have now finished viewing class details
Thank you for using this program
>>> # Exits the program
Im Gegensatz dazu (die Arbeit, aber ineffiziente Version):
Hello and welcome to my quiz.
Please write your name: teacher
Write the number of the class you would like to see (1, 2 or 3): 1
Opening Class 1
_________________________________________
| |
| 1) Alphabetical with highest score |
| 2) Highest score, highest to lowest |
| 3) Average score, highest to lowest |
|_________________________________________|
Choose one of the options above (1, 2 or 3): 1
Sorting alphabetically...
['Abdul: 8', 'Bruno: 5', 'Hello: 5', 'Lol: 10', 'Zaid: 9']
Would you like to see any other class details? yes
Write the number of the class you would like to see (1, 2 or 3): 1
Opening Class 1
_________________________________________
| |
| 1) Alphabetical with highest score |
| 2) Highest score, highest to lowest |
| 3) Average score, highest to lowest |
|_________________________________________|
Choose one of the options above (1, 2 or 3): 3
Sorting by average score, from highest to lowest
['Lol: 10.0', 'Zaid: 8.333333333333334', 'Abdul: 5.333333333333333', 'Hello: 3.3333333333333335', 'Bruno: 3.0']
Would you like to see any other class details? no
Okay...
You have now finished viewing class details
Thank you for using this program
>>>
Kann jemand bitte helfen Sie mir. Eine Vollversion von meinem Code ist verfügbar, wenn jemand will, dass überprüfen: http://www.filedropper.com/teacherprogramtask3-annotated
Bitte lesen Sie diese http://stackoverflow.com/help/how-to-ask und Frage. –
Danke ... Ich wusste einfach nicht, wie man die Codeformatierung macht, die Zondo gemacht hat. –