0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Python】娘との会話シミュレーター「家族の正体編」

Last updated at Posted at 2023-05-17

概要

3歳の長女が全知全能でした。急に家族の正体を語りだしたので、そのやりとりをPythonでやっつけプログラミングしました。

コード

def ask_shoutai():
    dict = {'':'神様', 'お母さん':'奥様', 'お父さん':'忍者', '':'赤ちゃん'}
    keys = ''
    for key in dict:
        keys = keys + ' ' + key
    print(f'[{keys} ]')
    print('------------')

    person = input('「だれ?」:')

    try:
        return print(f'{person}は、{dict[person]}!」')
    except:
        return print('「知らない」')

ask_shoutai()

実行結果

[ 私 お母さん お父さん 妹 ]
------------
「だれ?」:私
「私は、神様!」

[ 私 お母さん お父さん 妹 ]
------------
「だれ?」:お父さん
「お父さんは、忍者!」

[ 私 お母さん お父さん 妹 ]
------------
「だれ?」:お父さんは、黒以外の服も着た方がいいと思う?
「知らない」

変数名の付け方とか、デファクトスタンダードを知ってそれに合わせたい…

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?