LoginSignup
0
0

More than 3 years have passed since last update.

UdemyのPythonコースをやってみる〜

Last updated at Posted at 2020-06-27

 きっかけ

最近もう一度Pythonを勉強し直そうと思ったからちょっと前に購入していたUdemyのPythonコースを最初からやってみました。

 とりあえず始めよう

久しぶりにPythonを触るので初歩の初歩から

test.py
print("Hello World")

そんでもって変数

test.py
a = 12
b = 14

total = a + b
# 26が出力されるよ
print(total)

次はString
ここで初めてf""の存在を知る。。
(お前は本当にかつてPythonを学んだのか??という疑問はさておき)

test.py
name = "Bob"
greeting = f"Hello,{name}"
# Hello Bobが出力されるよ
print(greeting)

name = "Tom"

print(f"Hello,{name}")
# Hello Tomが出力されるよ

そしたら次はInput
なんとなくcm⇛inchに変換するようにしてみる

test.py
size_input = input("How tall you are in cm? : ")
hight_cm = int(size_input)
hight_inc = hight_cm * 0.39
print(f"{hight_cm} cm is {hight_inc: .2f} inches.")

#出力
# How tall you are in cm? : 178
# 178 cm is  69.42 inches.

で、最後にまとめ
さっきのコードをちょっといじって入力された年数を月に変換するようにしてみたよ

test.py
age_input = int(input("How old are you?"))
age_month = age_input * 12
print(f"You are {age_input} old then {age_month} months.")

#出力
#How old are you?33
#You are 33 old then 396.

今回は一旦ここまで

本当に初歩の初歩過ぎて記事をアップすることも恥ずかしいけどとりあえず忘備録兼自分のモチベアップのために上げていきます。
次はList,Tuple,setあたりから忘備録をつけていこう。 

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