实验3
2021/4/18 18:25:20
本文主要是介绍实验3,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
x=list(range(10)) print('整数输出1:',end='') for i in x: print(i,end=' ') print('\n整数输出2:',end='') for i in x: print(f'{i:02d}',end = '-') print('\n整数输出3:',end ='') for i in x[:-1]: print(f'{i:02d}',end = '-') print(f'{x[-1]:02d}') print('\n字符输出1:',end = '') y1=[str(i)for i in range(10)] print('-'.join(y1)) print('字符输出2:',end = '') y2=[str(i).zfill(2) for i in range(10)] print('-'.join(y2)
print('整数列表: ') x = list(range(97, 97+26)) for i in x: print(i, end = ' ') print('\n字符列表1: ') lower_alpha=[chr(i) for i in range(97,97+26)] for i in lower_alpha: print(i, end = ' ') print('\n字符列表2: ') upper_alpha = [i.upper() for i in lower_alpha] for i in upper_alpha: print(i, end = ' ')
import random import string print('用列表存储随机整数: ') ls = [random.randint(1, 100) for i in range(5)] print(ls) print('\n用集合存储随机整数: ') s = {random.randint(1,100) for i in range(5)} print(s) print('\n\n字母串: ', end = '') alpha = string.ascii_letters print(alpha) print(type(alpha)) print('\n数字串:', end = '') digits = string.digits print(digits) print(type(digits))
import random print('用集合存储随机整数: ') while True: s = {random.randint(1,100) for i in range(5)} print(s) if len(s) < 5: break
list=[] count=-1 #设置初始计数 n1=0 n2=1 list.append(n1) list.append(n2) while n1<1000 and n2<1000: n=n1+n2 if n<1000: list.append(n) n1=n2 n2=n for i in list: count += 1 #开始计数 if count % 5 == 0: #每5个换行 print(end='\n') print(f'{i:5d}',end=' ')
import random i=2 print('猜猜2021年5月哪一天是你的lucky day 你有3次机会 猜吧') x=int(input('请输入你想要猜的天数(1-31):')) y=random.randint(1,31) while x!=y: if i <= 3: if x<y: print('猜早啦') i+=1 x=int(input('再猜,请输入你想要猜的天数(1-31):')) elif x>y: print('猜晚啦') i+=1 x=int(input('再猜,请输入你想要猜的天数(1-31):')) else: print('您的机会用完啦') break else: print('恭喜你,猜对啦')
x,n= eval(input('输入十进制整数x和要转换的进制n:')) list1 = [] list2 = [] while x//n!=0 : b = x//n a = x%n x = b list1.append(a) list2.append(b) list1.append(b) list3 = list1[::-1] for i in list3: print(i,end='')
这篇关于实验3的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-22项目:远程温湿度检测系统
- 2024-12-21《鸿蒙HarmonyOS应用开发从入门到精通(第2版)》简介
- 2024-12-21后台管理系统开发教程:新手入门全指南
- 2024-12-21后台开发教程:新手入门及实战指南
- 2024-12-21后台综合解决方案教程:新手入门指南
- 2024-12-21接口模块封装教程:新手必备指南
- 2024-12-21请求动作封装教程:新手必看指南
- 2024-12-21RBAC的权限教程:从入门到实践
- 2024-12-21登录鉴权实战:新手入门教程
- 2024-12-21动态权限实战入门指南