2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【まとめ】Python学習Day1〜5で学んだこと

2
Last updated at Posted at 2026-03-23

学んだこと(2026/03/14~03/19)

  1. 文字列
    • print()で文字列を出力できる
    • 文字列は'',""で囲う
    • コメントは#を付ける
    • 「+」で文字列同士を連結できる
  2. 数値
    • クォーテーションで囲まない
    • 四則演算→「+,-,*,/,%(余り)」
  3. 変数
    • 変数名=値で定義する
    • =は「右辺を左辺に代入する」という意味
    • 頭文字を数字にできない
    • 二語以上のときは単語の間に_を入れる
    • 「変数名 = 新しい値」で変数の値を上書きできる
    • x=x+10 は x+=10 に省略できる
  4. 型変換
    • 数値型を文字列型に変換するには「str」
    • 文字列型を数値型に変換したい場合には「int」
  5. 条件式
    • A==B → 左右の値が等しいときに成り立つ
    • A!= → 左右の値が等しくないときに成り立つ
    • if A==B :(インシデント)…
    • 大小を比べる比較演算子(>,>=,<,<=)
    • else,elif
    • and,or,if not
  6. リスト
    • リスト名=[要素1,要素2,要素3]
    • リスト名[インデックス番号]で要素名を取り出せる
    • 「リスト名[インデックス番号] = 要素名」でリストの更新
    • 「リスト名.append(要素名)」でリストの追加
    • 「for 変数名 in リスト名:」で要素を全て取り出す、繰り返し処理ができる
  7. 辞書
    • 辞書名={キー1: 要素1, キー2: 要素2, …}
    • 辞書名[キー名]で要素を取り出せる
    • 「辞書名[キー名] = 要素名」で辞書の更新
    • 「辞書名[新しいキー名] = 要素名」で辞書の追加
    • 「for 変数名 in 辞書名:」で要素を全て取り出す、繰り返し処理ができる
  8. その他
    • 「while 条件式: (インシデント)処理の内容(インシデント)処理後の変数更新の内容」という式で、条件式の間処理を繰り返すwhile文
    • 「条件式:(インシデント)break」という式で繰り返し処理を終了できる
    • 「条件式:(インシデント)continue」という式で、条件式の間処理をスキップできる

実際に書いたコード

money=1000

items = {'apple': 100, 'banana': 200, 'orange': 400}
for item_name in items:
    print('--------------------------------------------------')
    
    print(item_name + 'は1個' + str(items[item_name]) + '円です')
    
    input_count = input('購入する' + item_name + 'の個数を入力してください:')
    print('購入する' + item_name + 'の個数は' + input_count + '個です')
    
    count = int(input_count)
    total_price = items[item_name] * count
    print('支払い金額は' + str(total_price) + '円です')
    
    print('財布には'+str(money)+'円入っています')
    if money>=total_price:
        print(item_name+''+input_count+'個買いました')
        money-=total_price
    else:
        print('お金が足りません')
        print(item_name+'を買えませんでした')
2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?