coding-coworking-club / python-spring-2021

ccClub Python Spring 2021
https://www.ccclub.io/course/2021Spring
23 stars 6 forks source link

[Homework 3] 小明上菜啦 II #483

Closed RayZhao0310 closed 3 years ago

RayZhao0310 commented 3 years ago

提交連結

https://judge.ccclub.io/status/d657c495fcf4432bf5ea2f4db6b19cc5

程式碼

menu_dict = {}
#排序過的:原菜名
while True:
    menu = input()
    if len(menu) != 0:
        lower_menu = menu.lower()
        word_lst = []
        for i in range(len(menu)):
            word_lst.append(lower_menu[i]) 

        menu_sorted = "".join(sorted(word_lst))

        if menu_sorted in menu_dict:
            if menu == menu_dict[menu_sorted]:
                print(menu + " already exists")
            else:
                print(menu + " is " + menu_dict[menu_sorted] + ", " + menu_dict[menu_sorted] + " already exists")
        else: 
            menu_dict[menu_sorted] = menu
            print("Create "+ menu)
    else:
        break

錯誤訊息

問題描述

我的終止條件是設定為輸入長度為0時停止,中間的條件檢驗大致上跟hint 的提示一樣,是先把排序後結果丟進字典,再去比較。在 jupyter notebook 上時程式也可以進行,但是不知道為什麼在系統會是Runtime Error ,麻煩助教幫忙看看了,謝謝。

huaitzu commented 3 years ago

要運用 try except 來處理不定行輸入,而非你現在設立的終止條件喔!你可以參考我們提供的 虛擬碼 進行修改~

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.