LoginSignup

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.

More than 1 year has passed since last update.

コンピュータ演習A 21: Day 3rd(5/10) c3(Python print)

Last updated at Posted at 2021-05-10

認知テスト

Python: REPL, print, error message

codeやエラーを見る

  • file, folderの違い

  • コーディングの心得(Processingの場合)

  • 注意: 初心者のうちは,こういう細々とした操作をまとめてメモとして残しておくといいですよ.何か新しいことが出てきたら,そのメモに追記していくようにして.自分が覚えるのではなく,ノートが覚えてくれるように.コツは,ファイル名にキーワードを含めることと,どこに置くかを決めておくこと.一度できたことも,忘れるものだと覚悟して,どれだけ早くメモに辿り着くかの工夫をしてください.

  • 編集,実行,check

  • mac と win10 の違い

plot sample

# on plot.py (never name matplotlib.py)
  import matplotlib.pyplot as plt
  import numpy as np

  x = np.linspace(0, 20, 100)  # Create a list of evenly-spaced numbers over the range
  plt.plot(x, np.sin(x))       # Plot the sine of each x point
  plt.show()                   # Display the plot

macでは先にtck/tkを入れて(下で記述),terminalから

python test.py

すると表示される.

テキスト

  • いちばんやさしいPython入門教室1

  • いちばんやさしいPython入門教室2

  • print 色々

    ./python_codes/c3_python_print.py
    print("hello : " + str(1234 % 123))
    print("Hello world.")
    print('Hello world.')
    print("I'm Shigeto R. Nishitani")
    print('I\'m Shigeto R. Nishitani')
    #print("I'm Shigeto R. Nishitani : " + 1234 % 123)
    #  File "/Users/bob/Desktop/lecture_21s/CompAInfo/python/example03-05-01.py", line 6, in <module>
    #    print("I'm Shigeto R. Nishitani : " + 1234 % 123)
    # TypeError: can only concatenate str (not "int") to str
    print("I'm Shigeto R. Nishitani : " + str(1234 % 123))
    print("I'm Shigeto R. Nishitani : \n" + str(1234 % 123))
    
    # 改行付きで出力
    print("""I'm Shigeto R. Nishitani : 
    print(str(1234 % 123))""")
    
    # 改行なしで出力
    print("I'm Shigeto R. Nishitani : ", end='')
    print(str(1234 % 123))
    
    # 愛してるって100回叫ぶ
    print("愛してる!"*100)
    
    # ¥記号, Mac US Keyboardでは'option-y'
    print("¥120,000,000\n")
    # win10ではkeyboardでは無理みたい.日本語で半角にするか,次のようにchrで指定.
    print(chr(165)+"120,000,000\n")
    

LUNA提出課題

エラーの英語をちゃんと読もう.

  • Pythonを動かしたときにVS Codeに表示されたエラーの英語をコピー,

  • エラーの日本語訳とその時の状況を説明,

  • その原因と解決方法を記述

  • 注意: 初心者のうちはこの作業記録を残しておくといいですよ.自分のエラー集みたいな感じで.それを見直すと自分の癖がわかりますから.

codeの添付ファイルでの提出

テキスト第3章のprint関数関連のcodeと出力結果をLUNAに添付ファイルとして提出してください.

ファイルへの出力と中身の確認

Anaconda promptを使って出力結果をファイルへ保存する方法を紹介します.

terminal(mac) win10 or 11(cmd.exe) 説明
> [FILE] > [FILE] 出力のredirection(方向を変える,出力先の変更)
>> [FILE] >> [FILE] FILEへ追記
cat [FILE] type [FILE] 中身の出力
  1. python example03-05-04.py > hello.txt
  2. cat hello.txt (win11 :: type hello.txt)
  3. open . (win11 :: explorer.exe .)からファイルをbrowserにdrag&drop.

  • source ~/Desktop/lecture_22s/CompAInfo/c3_print.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