-1
조건이 충족되지 않아도 어떤 이유로 프로그램이 'else'파트로 이동하지 않습니다.이 if 문에 어떤 문제가 있습니까?
if score_str >= 3:
print("Pass")
self.prefect = tk.Label(self, width=80, height=4, text = "You have passed, well done! You can now become a prefect.")
self.prefect.pack(side="top", fill="both", expand=True)
self.name = tk.Label(self, width=80, height=4, text = student_name)
self.name.pack(side="top", fill="both", expand=True)
self.surname = tk.Label(self, width=80, height=4, text = student_surname)
self.surname.pack(side="top", fill="both", expand=True)
self.tutor = tk.Label(self, width=80, height=4, text = student_tutor_group)
self.tutor.pack(side="top", fill="both", expand=True)
else:
print("Fail")
self.fail = tk.Label(self, width=80, height=4, text = "Unfortunately you have not scored highly enough to be considered for a prefect position.")
self.fail.pack(side="top", fill="both", expand=True)
여기에서 우리에게 더 많은 것을 제공해야합니다. 우리를 위해 그것을 데모해라. 그리고 가장 간단한 예제로 제거하십시오 (가능한 한 많은 다른 줄을 제거하십시오). 대개 여기에 게시해야하기 전에 문제가 해결됩니다. – Crisfole
몇 가지 기본 디버깅을 통해이를 직접 해결할 수 있습니다. 1 단계 :'4> = 3' ->'True' (당신이 미쳐 버리지 않도록). 2 단계 :'type (score_str)'. 완료 : p. 내가 말하는 건 서두르지 마라. – keyser
@ ᴋᴇʏsᴇʀ : 파이썬 유형에 대해 충분히 알고 있다고 가정합니다. 일부 다른 언어에서는 자릿수를 포함하는 문자열이 자동으로 강제 변환되고 비교는 숫자로 이루어집니다. 파이썬 2는 문자열과 숫자를 비교할 수 있도록 실수를 했으므로 혼합 유형을 포함하는 목록을 정렬 할 수 있습니다. 그 때문에 이런 혼란이 야기됩니다. 적어도 파이썬 3은이 실수를 할 때 예외를 발생시킵니다. –