class User:
def __init__(self, name, grades):
self.name = name
self.grades = grades
def average(self):
return sum(self.grades) / len(self.grades)
userName = input("Enter your name: ")
userGrades = []
while True:
userGradesInput = input("Enter your grades and write 'stop' to stop entering: ")
if userGradesInput == int:
userGrades.append(userGradesInput)
if userGradesInput == "stop":
break
print(userGrades)
따라서 프로그램을 실행하고 계속해서 나이를 추가해도 목록은 여전히 비어 있습니다. 누군가가 문제가 무엇인지 말해 줄 수 있고 그것을 복잡하게 만들지 마십시오.
나는 당신이 당신의 목록에 입력 (등급)을 추가하려고 시도하고 있다고 생각합니다. 다음과 같이해야합니다.
userGradesInput = input("Enter your grades and write 'stop' to stop entering: ")
if userGradesInput.isdigit(): # check whether input is int or not like this
userGrades.append(int(userGradesInput))
elif userGradesInput == "stop":
break
if userGradesInput == int:
실제로 정수인지 아닌지 확인하지 않을 때 , <class 'int'>
파이썬 의 내장형과 같은지 비교합니다. 이것은 잘못되고 의미가 없습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다