Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

試合形式の選択でDictを活用することでコード短縮 #1

Open
fim-user opened this issue Sep 17, 2021 · 0 comments
Open

Comments

@fim-user
Copy link

controllers/apps.py

game_format_list_num = ["1番", "2番", "3番", "4番", "5番"]
select_game_format = radio("試合形式を選択して下さい:", options=game_format_list_num)
if select_game_format == "1番":
    select_game_format = 1
    toast(game_format_list[1] + "という試合形式で試合開始です!", duration=3, position='left')
elif select_game_format == "2番":
    select_game_format = 2
    toast(game_format_list[2] + "という試合形式で試合開始です!", duration=3, position='left')
elif select_game_format == "3番":
    select_game_format = 3
    toast(game_format_list[3] + "という試合形式で試合開始です!", duration=3, position='left')
elif select_game_format == "4番":
    select_game_format = 4
    toast(game_format_list[4] + "という試合形式で試合開始です!", duration=3, position='left')
elif select_game_format == "5番":
    select_game_format = 5
    toast(game_format_list[5] + "という試合形式で試合開始です!", duration=3, position='left')
return select_game_format


game_format_list_num = ["1番", "2番", "3番", "4番", "5番"]

game_format_list_num = {"1番": 1, "2番": 2, "3番"...
とDictで定義するとその後の処理を

select_game_format = game_format_list_num[select_game_format]
toast(game_format_list[select_game_format] + "という試合形式で試合開始です!", duration=3, position='left')

だけの記述ですみます。(変数名などはわかりにくさを生むので別途修正の必要あり)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant