首页 > 其他分享 >控制语句与组合数据类型应用

控制语句与组合数据类型应用

时间:2023-04-25 23:14:55浏览次数:32  
标签:语句 %- 组合 数据类型 cart products 10s print input

import random
print('用列表存储随机整数: ')
lst = [random.randint(0, 100) for i in range(5)]
print(lst)
print('\n用集合存储随机整数: ')
s1 = {random.randint(0, 100) for i in range(5)}
print(s1)
print('\n用集合存储随机整数: ')
s2 = set()
while len(s2) < 5:
    s2.add(random.randint(0, 100))
print(s2)

 

lst = [55, 92, 88, 79, 96]
i = 0
while i < len(lst):
    print(lst[i], end=' ')
    i+=1
print()
for i in range(len(lst)):
    print(lst[i], end = ' ')
print()
for i in lst:
    print(i , end = ' ')

 

print()

book_info = {'isbn': '978-7-5356-8297-0','书名': '白鲸记','作者': '克里斯多夫.夏布特','译者': '高文婧','出版社': '湖南美术出版社',
'售价': 82}
for key, value in book_info.items():
    print(f'{key}: {value}')
print()
for item in book_info.items():
    print(f'{item[0]}: {item[1]}')
print()
for value in book_info.values():
    print(value, end = ' ')
print()
for key in book_info.keys():
    print(book_info[key], end = ' ')

 

x='''The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!'''
y=x.lower()
z=[]
d={}
for i in y:
    if 'a'<= i <='z':
        z.append(i)
for i in z:
    d[i]=d.get(i,0)+1
for i in range(26):
    if chr(97+i) not in d:
        d[chr(97+i)]=0
    else:
        continue
a=[(value,key) for key,value in d.items()]
a=sorted(a,reverse=True)
for i in a:
    print(f'{i[1]}:{i[0]}')

x='专业代号信息'
print('{:-^20s}'.format(x))
d={'8326':'地信类','8329':'计算机类','8330':'气科类','8336':'防灾工程','8345':'海洋科学','8382':'气象工程'}
for i in d:
    print(f'{i}:{d[i]}')
x='学生专业查询'
print('{:-^20s}'.format(x))
n=input('请输入学号:')
if n!='#':
    while n!='#':
        x=n[4:8]
        if x not in d :
            print('不在这些专业中...')
            n=input('请输入学号:')
        else:
            print(f'专业是:{d[x]}')
            n=input('请输入学号:')
    print('查询结束')
else:
    print('查询结束')

import random
xO = random.randint(1,31)
print('猜猜2023年5月哪一天是你的lucky day

标签:语句,%-,组合,数据类型,cart,products,10s,print,input
From: https://www.cnblogs.com/lv1883405/p/17332468.html

相关文章

  • 实验3 控制语句与组合数据类型应用编程
    实验任务11importrandom2print('用列表存储随机整数:')3lst=[random.randint(0,100)foriinrange(5)]4print(lst)5print('\n用集合存储随机整数:')6s1={random.randint(0,100)foriinrange(5)}7print(s1)8print('\n用集合存储随机整数:......
  • 流程控制语句 ——if语句
    一if(关系表达式){语句体;}流程:首先计算关系表达式的值如果关系表达式的值为true就执行语句体如果关系表达式的值为false则执行继续执行后面其他语句 二if(关系表达式){语句体1;}else{语句体2;}流程:计算关系式的值如果关系式的值为true执行语......
  • 数据类型_字符串
    一个字符串类型键允许存储的数据的最大容量是512MB,不知道现在限制放宽了没有1、赋值、取值可以存储任何形式的字符串set、get是redis中最简单的两个命令  2、递增数字   ......
  • 实验3 控制语句与组合数据类型应用编程
    task1程序源码:1importrandom23print('用列表储存随机整数:')4lst=[random.randint(0,100)foriinrange(5)]5print(lst)67print('\n用集合存储随机整数:')8s1={random.randint(0,100)foriinrange(5)}9print(s1)1011print('\......
  • 实验3 控制语句与组合数据类型应用编程
    task1.pyimportrandomprint('用列表存储随机整数:')lst=[random.randint(0,100)foriinrange(5)]print(lst)print('\n用集合存储随机整数:')s1={random.randint(0,100)foriinrange(5)}print(s1)print('\n用集合存储随机整数:')s2=set()whi......
  • 面试官:Java 中有几种基本数据类型是什么?各自占用多少字节?
    认识基本数据类型在学习基本数据类型之前,我们先认识一下这两个单词:1、bit--位:位是计算机中存储数据的最小单位,指二进制数中的一个位数,其值为“0”或“1”。2、byte--字节:字节是计算机存储容量的基本单位,一个字节由8位二进制数组成。在计算机内部,一个字节可以表示一个数据,也可以表......
  • 实验3 控制语句与组合数据类型应用编程
    实验任务1实验源码1importrandom23print('用列表存储随机整数:')4lst=[random.randint(0,100)foriinrange(5)]5print(lst)67print('\n用集合存储随机整数:')8s1={random.randint(0,100)foriinrange(5)}9print(s1)1011print('......
  • 实验3 控制语句与组合数据类型应用编程
    一.实验目的:1.知道Python中组合数据类型字符串(str)、列表(list)、元组(tuple)、集合(set)、字典的表示、特性2.能够正确、熟练使用字符串(str)、列表(list)、元组(tuple)、集合(set)、字典的常用操作3.针对具体问题场景,能够灵活、组合使用多种数据类型,应用或设计算法,使用......
  • 实验3 控制语句和组合数据类型应用编程
    task1.py1importrandom2print('用列表存储随机整数:')3lst=[random.randint(0,100)foriinrange(5)]4print(lst)5print('\n用集合存储随机整数:')6s1={random.randint(0,100)foriinrange(5)}7print(s1)8print('\n用集合存储随机整数......
  • 模糊查询+首字母查询组合框
     <spanclass="label">站名称:</span><divid="selectMain"><inputid="myInputOne"name="Q_bdzmc_S"onkeyup="InputAndSelect.ke......