変数のデータ型と演算

ソースコード

#coding:utf-8
# 最初のプログラミング:変数

#coding:utf-8
# 最初のプログラミング:変数と変数の型(type)
import os
import math

os.system("clear")

# 数値
a=1
print(type(a),"a=",a)
b=2.23
print(type(b),"a=",b)

# 文字と文字列
a='h'
print(type(a),"a=",a)

a="hello world!"
print(type(a),"a=",a)

a="23456789"
print(type(a),"a=",a)
a='''
        小俣
        慶恭
        です
'''
print(type(a),"a=",a)

# 論理的なデータ(真true、偽false)
a=20
b=34
c= a==b
print(type(c),"c=",c)
# 以上 >=
c= a>=b
print(type(c),"c=",c)
# 等しくない !=
c= a!=b
print(type(c),"c=",c)

c= bool(1)
print(type(c),"c=",c)

c= bool(0)
print(type(c),"c=",c)

# 四則演算
print(2*(3+4)*5/2)

a,b,c=12,23,45
print(a-b+c)

a,b=100,23
a *= b
print(a)

# 出力関数のフォーマット(format)設定
r=50
area=math.pi*math.pow(r,2)
print(f'半径={r}面積={area:.2f}')

lenth=2*math.pi*r
print(f'半径={r}面積={lenth:.2f}')

product_name="りんご"
app_price=120
tax_rate=0.08
qty=5
total_price=(1+tax_rate)*app_price*qty
print(f'{product_name} {total_price:.0f}円\n 単価{app_price}円 消費税{tax_rate} 購入個数{qty}')


product_name="石鹸"
app_price=300
tax_rate=10/100
qty=3
total_price=(1+tax_rate)*app_price*qty
print(f'{product_name}  {total_price:.0f}円\n 単価{app_price}円 消費税{tax_rate} 購入個数{qty}')


 
実行結果