Day2_Language Elements

"""
使用变量保存数据并进行算术运算
Author:黄骏捷
Date:2019-09-28
"""

a=123
b=321
print(a+b)
print(a-b)
print(a*b)
print(a/b)
print(a//b)
print(a%b)
print(a**b)
print('-------------------------')

"""
使用type()检查变量的类型
"""
c=12.345
k=1+5j
d='hello,world'
e=True
print(type(a))
print(type(c))
print(type(k))
print(type(d))
print(type(e))
print('-------------------------')

"""
使用input()函数获取键盘输入(字符串)
使用int()函数讲输入的字符串转换成整数
使用print()函数输出带占位符的字符串
"""
a = int(input('a = '))
b = int(input('b = '))
#print(a+b)
print('%d + %d = %d' % (a,b,a+b))
print('%d + %d = %f' % (a,b,a/b))
print('------------------------------')
"""
Example 1:华氏温度转换成摄氏温度
公式:$C=(F-32)\div 1.8$
"""
f = float(input('请输入华氏温度: '))
c = (f-32)/1.8
print('%.1f 华氏度 = %.1f摄氏度' %(f,c))
print('------------------------------')
"""
Example 2:根据半径计算周长和面积
"""
import math
radius = float(input('请输入圆的半径: '))
perimeter = 2*math.pi*radius
area = math.pi*radius**2
print('周长:%.2f    面积:%.2f' %(perimeter,area))
发布了66 篇原创文章 · 获赞 45 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/ACofKing/article/details/101792405