Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

コンピュータ演習A 25 : d9(6/16) Python-III(chap 5)_debug

Last updated at Posted at 2023-06-05

学ぶ項目

  • どこに注目するか
    • シンボル文字とその名前
    • separator(区切り),いろんなカッコ
      • 名前をつけると区別がつく,chunkingの第一歩

img

img

  • codeの小ネタ
    • ブラウザ(エクスプローラのトグル): ctrl-b #macではcommand-b
    • terminalへ移動: alt-tab, # command-tab

課題

記憶のプレゼン

  • d9_memory_competitionにxlsxをupload.

Python課題

  1. python codeファイルの名前は自由です.中身がわかり,しかも補完がしやすいのがいいです.
    1. Lesson5-2の1桁乱数のhit_and_blowを作りなさい(e5-2_one_digit.py).
    2. Lesson5-3の4桁乱数を生成して表示するcodeを加えて,出力を確かめなさい(e5-3_four_digit.py).
    3. Lesson5-4の入力をチェックするcodeと,動作の入出力を確かめなさい(e5-4_check_input.py).
    4. Lesson5-5のhit and blowをチェックするcodeと,動作の入出力を確かめなさい(e5-5_check_hit_and_blow.py).
    5. 全体code(教科書pp.147-8に相当)と,動作の入出力を確かめなさい(e5_final.py).
  2. d9_hit_and_blow.mdにまとめなさい
    1. d9_hit_and_blow.mdを作成し,

    2. 新しく学んだことをメモしていきなさい.

    3. 出てきたError, バグとその原因,解決策を記述しなさい.

    4. 編集途中のコードを

      1. codeをpythonブロックに,
      2. 入出力の様子をbash ブロックに

      貼り付けなさい.

最終課題

pythonで何か動くものを作ってください.最終日(7/08 or 15)にプレゼンしてもらい,相互評価で点数をつけます.

オプション課題

以降は,高度なプログラマを目指す人のためのオプション課題です.採点からは省きます.

一桁版のtemplate

下の課題解答例(one_digit_template.py)を参照して,全体の流れがわかるようにコメントを加えた版を作ってみなさい.

関数化

前節のコメント部分を関数化してみなさい.

  • endless_loopとending_processはそのままでいいです.

hit_and_blowの改善

教科書のhit_and_blow_check codeにはバグがあります.「リンク」を参照して完動版を作ってみなさい.

課題解答例(one_digit_template.py)

最終codeはchunkingした後のような状態です.途中の試行錯誤を記録していくことが,mdでmemoをとる目的です.それが,頭に残るコツだから.

次のcodeは完成版ですが,どのように組み上げていくかをフォローしてください.このような 所作習得法 を「写経」と呼んでいます.

# one-digit code

# make random number
import random
a = random.randint(0,9)
print(a)

# endless loop
while True:
    # check input
    b_tmp=input("type number:>")
    b = int(b_tmp)
    print(repr(b)) # representation

    # check hit and blow
    hit = 0
    if a==b:
        hit = 4
        print("hit")
    else:
        print("missed")
    
    # ending process
    if hit == 4:
        break
> python one_digit.py 
3
type number:>2
2
missed
type number:>4
4
missed
type number:>3
3
hit

  • source ~/Desktop/lecture_25s/comp_a_25s/python/orgs/d9_hit_and_blow.org
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?