# 1、'ax' < 'xa' 结果为: True
# 2、以下程序如果输入666执行哪个语句?为什么
# 程序执行'if执行了'语句, == 与 or 相比较 ==优先,
# temp == 'YES' or 'yes' 中'YES'与temp比较,因YES永远为Ture,
# 将永远执行第一条语句,即使为False or 'yes'比较也为True执行
# 第一条语句。
temp = input("请输入:")
if temp == 'YES' or 'yes':
print('if执行了')
else:
print('else执行了')
----------------
#练习代码
#(x//y,x%y) 取整,取模(取余)
a = divmod(10,3)
print(a)
#
#小数 导入源代码
from decimal import Decimal
b = Decimal('0.1')+Decimal('0.6')+Decimal('0.1')-Decimal('0.3')
print(b)
#类型转换
weight = 44.7
print(type(weight))
print(int(weight))
#导入内置模块调用函数 ceil()向上取整 floor()向下取整 pow()次幂
import math
print(math.ceil(4.1)) # 执行结果4
print(math.floor(4.5)) # 5
print(math.pow(2,3)) # 8.0 = 2**3次幂
# #四舍五入
#round()
#内置方法 python3中是四舍六入五双飞
a = round(4.5) # 4是双数结果4
a1 = round(3.5) # 3是单数结果 4
a2 = round(7.5) # 7是单数结果 8
a3 = round(8.5) # 8是双数结果 8
print(a,a1,a2,a3)
# 函数
print(abs(-1)) # 执行结果:1 abs() 取绝对值
print(math.ceil(4.1)) # 向上取整
print(math.floor(2.3)) # 向下取整
print(math.pow(2,3)) #次幂
print(math.modf(1.5)) # 执行结果:(0.5, 1.0)小数部分和整数部分
print(max(9,8))# 执行结果:9 取最大值
print(min(9,8))# 执行结果:8 取最小值
print(math.sqrt(2)) # 执行结果1.4142135623730951 2的平方根
python基础-练习(二)
猜你喜欢
转载自blog.csdn.net/weixin_45905671/article/details/104079262
今日推荐
周排行