CS50P PSET3: Почему мой код не проходит проверку 50 на наличие проблемы с продуктами?Python

Программы на Python
Anonymous
CS50P PSET3: Почему мой код не проходит проверку 50 на наличие проблемы с продуктами?

Сообщение Anonymous »

Набор проблем, которые я пытаюсь решить: CS50P 2022 psets/3/grocery/
Код, который я написал:

Код: Выделить всё

# Syntax of dict = {'key': value}
mydict = {}

# Infinite loop with break
while True:
try:
item = input().upper()
# Search if item matches a key inside the dict
if item in mydict:
mydict[item] = mydict[item] + 1
else:
mydict[item] = 1
except EOFError:
for i in mydict:
print(mydict[i], i)
break
Результаты check50:

Код: Выделить всё

Results for cs50/problems/2022/python/grocery generated by check50 v3.3.7
:) grocery.py exists
:) input of EOF halts program
:) input of "apple" and "banana" yields "1 APPLE 1 BANANA"
:) input of "strawberry" and "strawberry" yields "2 STRAWBERRY"
:) input of "mango", "sugar", and "mango" yields "2 MANGO 1 SUGAR"
:( input of "tortilla" and "sweet potato" yields "1 SWEET POTATO 1 TORTILLA"
expected "1 SWEET POTATO...", not "\n\n1 TORTILLA..."
Как видно выше, проверка 50 не удалась:

Код: Выделить всё

:( input of "tortilla" and "sweet potato" yields "1 SWEET POTATO 1 TORTILLA"
expected "1 SWEET POTATO...", not "\n\n1 TORTILLA..."
Но когда я запускаю python food.py, результат, похоже, соответствует ожидаемому:

Код: Выделить всё

tortilla
sweet potato
1 TORTILLA
1 SWEET POTATO
Мне трудно понять, где я допустил ошибку. Пожалуйста, помогите.


Подробнее здесь: https://stackoverflow.com/questions/743 ... ry-problem

Вернуться в «Python»