Python-100-Days-Day2

python运算符

a = 321
b = 123
print(a + b)
print(a - b)
print(a * b)
print(a / b)
print(a // b)#取整除
print(a % b)#取余
print(a ** b)#a的b次幂

a = int(input('a = '))#只能赋值为int类型
b = int(input('b = '))
print('%d + %d = %d' % (a, b, a + b))
print('%d - %d = %d' % (a, b, a - b))
print('%d * %d = %d' % (a, b, a * b))
print('%d / %d = %f' % (a, b, a / b))
print('%d // %d = %d' % (a, b, a // b))
print('%d %% %d = %d' % (a, b, a % b))
print('%d ** %d = %d' % (a, b, a ** b))

a = 100
b = 12.345
c = 1 + 5j#复数
d = 'hello, world'
e = True
print(type(a))
print(type(b))
print(type(c))
print(type(d))
print(type(e))


a = 5
b = 10
c = 3
d = 4
e = 5
a += b
a -= c
a *= d
a /= e
print("a = ", a)

flag1 = 3 > 2
flag2 = 2 < 1
flag3 = flag1 and flag2
flag4 = flag1 or flag2
flag5 = not flag1
print("flag1 = ", flag1)
print("flag2 = ", flag2)
print("flag3 = ", flag3)
print("flag4 = ", flag4)
print("flag5 = ", flag5)
print(flag1 is True)
print(flag2 is not False)


'''
444
198
39483
2.6097560975609757
2
75
199580904170858944588683464608694075062943107082809027605498347841561605181074274426665986623764972439807786764739130193391688887305693295698132008415537889753720415793877902074665765736230030622222862498385818118244547668141388643750880896837470534556730014314212951333550122949806119583030226121714710874561
a = 3
b = 7
3 + 7 = 10
3 - 7 = -4
3 * 7 = 21
3 / 7 = 0.428571
3 // 7 = 0
3 % 7 = 3
3 ** 7 = 2187
<class 'int'>
<class 'float'>
<class 'complex'>
<class 'str'>
<class 'bool'>
a =  9.6
flag1 =  True
flag2 =  False
flag3 =  False
flag4 =  True
flag5 =  False
True
False
进程完成,退出码 0
'''
'''练习:华氏温度转摄氏温度'''
f = float(input('请输入华氏温度: '))
c = (f - 32) / 1.8
print('%.1f F = %.1f OC' % (f,c))

'''
请输入华氏温度: 65
65.0 F = 18.3 OC
'''
'''练习:计算圆的周长和面积'''
import math

radius = float(input('请输入圆的半径: '))
perimeter = 2 * math.pi * radius
area = math.pi * radius * radius
print('周长: %.2f' % perimeter)
print('面积: %.2f' % area)

'''
请输入圆的半径: 13.5
周长: 84.82
面积: 572.56
'''
'''练习:判断闰年'''
year = int(input('请输入年份: '))
is_leap = (year % 4 == 0 and
           year % 100 != 0 or
           year % 400 == 0)
print(is_leap)

'''
请输入年份: 2018
False
'''
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值