1、
count=eval(input("请输入两位数"))
jin=count//16
liang=count%16
print(jin,"斤",liang,"两")
2、
num=eval(input("请输入一个三位数:"))
res=0
res+=num%10
res+=num%100//10
res+=res//100
print("res=",res)
3、
4、字符串比大小:比较首字母的ASCII值
5、
6、
data1=eval(input("请输入第一个整数:"))
data2=eval(input("请输入第二个整数:"))
print("交换前:",data1,data2)
#方式一
# temp=data1
# data1=data2
# data2=temp
#方式二
# data1=data1^data2 #011(3)^101(5)=110
# data2=data1^data2 #110^101=011(3)
# data1=data1^data2 #110^011=101(5)
#方式三
data1,data2=data2,data1
print("交换后:",data1,data2)
7、
year=eval(input("请输入一个年份:"))
if(year%4==0 and year%100!=0) or(year%400==0):
print("是闰年")
else:
print("不是闰年")
8、
# from machine import Pin
# led1=Pin(15,Pin.OUT)
# led2=Pin(2,Pin.OUT)
# led3=Pin(0,Pin.OUT)
# led4=Pin(4,Pin.OUT)
score=eval(input("请输入一个分数:"))
if 90<=score<=100:
print("优秀")
# led1.value(1)
# led2.value(1)
# led3.value(1)
# led4.value(1)
elif 80<=score<90:
print("良好")
# led1.value(1)
# led2.value(1)
# led3.value(1)
# led4.value(0)
elif 60<=score<80:
print("及格")
# led1.value(1)
# led2.value(1)
# led3.value(0)
# led4.value(0)
elif 0<=score<60:
print("不及格")
# led1.value(1)
# led2.value(0)
# led3.value(0)
# led4.value(0)
else:
print("输入错误")
# led1.value(0)
# led2.value(0)
# led3.value(0)
# led4.value(0)
9、
num1=eval(input("请输入第一个数:"))
num2=eval(input("请输入第二个数:"))
num3=eval(input("请输入第三个数:"))
if num1>num2:
if num1>num3:
print("max=",num1)
else:
print("max=",num3)
else:
if num2>num3:
print("max=",num2)
else:
print("max=",num3)
10、
sum=0
while sum<=100:
num=eval(input("请输入一个数:"))
sum+=num
print("数字和:",sum)
print("while循环结束")
11、
num=100
while num<1000:
num_1=num%10
num_2=num//10%10
num_3=num//100
if num==(num_1**3+num_2**3+num_3**3):
print(num)
num+=1
12、
height=100.0
#1,2,3,4,5,6,7,8,9,10
for i in range(1,11):
height=height/2
print("第%d次落地高度:"%i,height)
13、
for num in range(2,51):
item =2
while item<=num-1:
if num%item==0:
break
item+=1
else:
print(num)
14、
line=eval(input("行数:"))
for i in range(0,line):
for j in range(0,i+1):
print("*",end="")
for k in range(0,i):
print(".",end="")
print()#换行
15、
alcohol=eval(input("请输入酒精含量(mg/100ml):"))
if alcohol>=20:
if alcohol>=80:
print("醉酒驾驶")
else:
print("酒后驾驶")
else:
print("没有酒后驾驶")
16、
import random
num=random.randint(1,100)
print("====游戏开始====")
for count in range(1,8):
guess_num=eval(input("请输入你猜测的数字:"))
if guess_num>num:
print("猜大了,剩余",7-count,"次机会")
elif guess_num<num:
print("猜小了,剩余",7-count,"次机会")
else:
print("猜对了")
score=100-10*(count-1)
print("本次游戏得分:",score)
break;
else:
score=0
print("次数用尽")
17、
18、
19、
s2="ABCDEFG"
print(s2[2:5:1])#BCD
print(s2[1:6:2])#BDF,MPY仅支持步长为1
print(s2[:4])#ABCD
print(s2[4:])#EFG
print(s2[-1:-5:-1])#GFED
print(s2[-5:-1])#CDEF
20、
name="jiangwbqwsd"
age=35
height=1.78
print("%s今年%d岁,身高是%.2f米"%(name,age,height))
year,month,day=2024,6,12
print("%d-%02d-%d"%(year,month,day))#%02d:数据宽度占两个字符,如果不够两个字符用0填充
21、
# 1.让用户输入两次密码
passwd = input("请输入密码:")
passwd2 = input("请再次输入密码:")
if passwd != passwd2:
print("两次输入的密码不一致")
exit() # 退出
# 2.判断密码长度是否超过16个字符,如果超过就截断
if len(passwd) > 16:
passwd = passwd[0:16]
# 3.判断密码是否包含了非法字符
number = "0123456789"
letter = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
symbols = r"""_-(){}\/|!@#$%^&*[]<>,.?"""
# 遍历检查用户输入密码是在支持的字符范围内
for ch in passwd:
if ch not in number+letter+symbols:
print("密码中包含了非法字符")
exit()
# 4.计算密码长度(判断密码强弱的依据)
passwd_len = len(passwd)
# 5.计算密码中包含了几种类别的字符
passwd_kind = 0
for ch in passwd: # 判断密码中是否包含数字类别的字符
if ch in number:
passwd_kind += 1
break
for ch in passwd: # 判断密码中是否包字母类别的字符
if ch in letter:
passwd_kind += 1
break
for ch in passwd: # 判断密码中是否包含符号类别的字符
if ch in symbols:
passwd_kind += 1
break
# 6.根据密码长度和密码包含的字符类别判断密码的强度
if passwd_kind == 1 or passwd_len < 8:
print("密码强度为低级(Low),只有中级或高级强度才允许")
elif passwd_kind == 2 and passwd_len >=8:
print("设置密码成功,密码强度为中级(Middle)")
elif passwd_kind == 3 and passwd_len >=8:
print("设置密码成功,密码强度为高级(High)")