x_y.py
# Python
x = int(input("请输入x:"))
y = int(input("请输入y:"))
print(x,'+',y,'=',x+y)
print(x,'*',y,'=',x*y)
print(x,'**',y,'=',x**y)
time.py
hour = int(input("请输入小时: "))
minute = int(input("请输入分钟:"))
second = int(input("请输入秒:"))
s = hour*60*60 + minute * 60 + second
print('从凌晨到现在经历了' ,s ,'秒')
if.py
# if.py
n = int(input("请输入一个整数: "))
if n % 2 == 1:
# 当成立时
print("这个数是奇数")
else:
# 当不成立时
print("这个数是偶数")
if_else.py
n = int(input('请输入一个数'))
# 判断这个数是否大于100
if n > 100:
print(n, "大于100")
else:
print(n,"不大于100")
# 2)判断这个数是否小于0
if n < 0:
print(n, '小于0')
else:
print(n, '不小于0')
# 3)判断这个数是否在80~100之间
if 80 < n < 100:
print(n, '在80~100之间')
else:
print(n, '不在80~100之间')
if2.py
# if2.py
# 输入一个数,用程序来判断这个数是正数,负数,还是零
n = int(input("请输入一个数: "))
if n > 0:
print("这个数是正数")
elif n = 0:
print("这个数是零")
elif n < 0:
print("这个数是负数")
image.png
elif.py
n = int(input("请输入一个季度1~4的整数"))
if n == 1:
print ('春季有1,2,3月')
elif n == 2:
print ('夏季有4,5,6月')
elif n == 3:
print ('秋季有7,8,9月')
elif n == 4:
print ('冬季有10,11,12月')
else:
print('你输入不是1~4的整数,你输错了')
image.png
month.py
n = int(input("请输入月份(1~12): "))
if 1 <= n <=3:
print("春季")
elif 4 <= n <= 6:
print("夏季")
elif 7 <= n <= 9:
print("秋季")
elif 10 <= n <= 12:
print("冬季")
else:
print("你输入有错")
if 语句嵌套
# 此示例示意if语句的嵌套
n = int(input("请输入月份(1~12): "))
# if 1 <= n <=3:
# print("春季")
# elif 4 <= n <= 6:
# print("夏季")
# elif 7 <= n <= 9:
# print("秋季")
# elif 10 <= n <= 12:
# print("冬季")
# else:
# print("你输入有错")
#
#
if 1 <= n <= 12:
if n <= 3:
print("春季")
elif n <= 6:
print("夏季")
elif n <= 9:
print("秋季")
else:
print("冬季")
else:
print("你输入有误!")
image.png
image.png
image.png
image.png
网友评论