首页 > 其他分享 >实验二

实验二

时间:2023-03-25 18:12:49浏览次数:29  
标签:%- 10.2 list 10d 实验 print 10s

task2-1源码

x="nba FIFA"
print(x.upper())
print(x.lower())
print(x.swapcase())
print()
x="abc"
print(x.center(10,'*'))
print(x.ljust(10,'*'))
print(x.rjust(10,'*'))
x="123"
print(x.zfill(10))
x=123
print(str(x).zfill(10))
print()
x="phone_number"
print(x.isidentifier())
x="222test"
print(x.isidentifier())
print()
x="  "
print(x.isspace())
x='\n'
print(x.isspace())
print()
x="python is fun"
table = x.maketrans("thon","1234")
print(x.translate(table))

  

task2-2源码

x=[5,11,9,7,42]
print('整数输出1:',end ='')
i=0
while i < len(x):
    print(x[i],end ='')
    i+=1

print('\n整数输出2:',end = '')
i = 0
while i <len(x):
    print(f'{x[i]:02d}',end = '-')
    i+=1

print('\n整数输出3:', end = '')
i = 0
while i <len(x)-1:
    print(f'{x[i]:02d}',end = '-')
    i+=1
print(f'{x[-1]:02d}')

print('\n字符输出1:',end = '' )
y1=[]
i=0
while i<len(x):
    y1.append(str(x[i]))
    i+=1
print('-'.join(y1))

print('字符输出2:',end = '')
y2=[]
i=0
while i<len(x):
    y2.append(str(x[i]).zfill(2))
    i+=1
print('-'.join(y2))

 task2-3源码

name_list = ['david bowie','louis armstrong','leonard cohen','bob dylan','cocteau twins']
i = 0
while i < len(name_list):
    print(name_list[i].title())
    i+=1

print()

t=[]
i = 0
while i <len(name_list):
    t.append(name_list[i].title())
    i+=1

print('\n'.join(t))

  

 task2-4源码

name_list = ['david bowie','louis armstrong','leonard cohen','bob dylan','cocteau twins']
x=sorted(name_list)
i = 0
while i < len(x):
    print(x[i].title())
    i+=1

 task2-5源码

import this
text = ('''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!''')
line = 0
word = 0
string = 0
space = 0
line = len(text.splitlines())
word = len(text.split())
string = len(text)
for i in text:
    if i == " ":
        space += 1
print('行数:{}'.format(line))
print('字数:{}'.format(word))
print('字符数:{}'.format(string))
print('空格数:{}'.format(space))

  

task2-6源码

book_list = [['静静的顿河','肖洛霍夫','金人', '人民文学出版社'],
             ['大地之上','罗欣顿.米斯特里','张亦琦', '天地出版社'],
             ['夜航西飞', '柏瑞尔.马卡姆', '陶立夏', '人民文学出版社'],
             ['来自民间的叛逆', '袁越', '','新星出版社'],
             ['科技与恶的距离', '珍妮.克里曼', ' 詹蕎語', '墨刻出版社'],
             ['灯塔','克里斯多夫.夏布特','吕俊君','北京联合出版公司'],
             ['小行星掉在下午','沈大成', '', '广西师范大学出版社']]
x = "图书信息"
print(x.center(20,'*'))
for i in range(len(book_list)):
    print('{}.《{}》|{}|{}'.format(i+1,book_list[i][0],book_list[i][1],book_list[i][-1]))

  

task2-7源码

data = ['99 81 75', '30 42 90 87', '69 50 96 77 89 93', '82 99 78 100']
num = 0
n = 0
for i in data:
    k = i.split()
    for m in k:
        num = num + int(m)
        n += 1
a = num/n
print('{:.2f}'.format(a))

task2-8源码

words_sensitive_list = ['张三', 'V字仇杀队', '杀']
comments_list = ['张三因生命受到威胁正当防卫导致过失杀人,经辩护律师努力,张三不需负刑事责任。','电影<V字仇杀队>从豆瓣下架了','娱乐至死']
m = 0
for i in comments_list:
    for m in words_sensitive_list:
        i = i.replace(m,"*"*len(m))
    print(i)

task2-9-1源码

"""
家用电器销售系统
v1.1
"""



#欢迎信息
print('欢迎使用家用电器销售系统')

#产品信息列表
print('产品和价格信息如下:')
print('**********************************************************')
print('%-10s'%'编号','%-10s'%'名称','%-10s'%'品牌','%-10s'%'价格','%-10s'%'库存数量')
print('----------------------------------------------')
print('%-10s'%'0001','%-10s'%'电视机','%-10s'%'海尔','%10.2f'%5999.00,'%10d'%20)
print('%-10s'%'0002','%-10s'%'冰箱','%-10s'%'西门子','%10.2f'%6998.00,'%10d'%15)
print('%-10s'%'0003','%-10s'%'洗衣机','%-10s'%'小天鹅','%10.2f'%1999.00,'%10d'%10)
print('%-10s'%'0004','%-10s'%'空调','%-10s'%'格力','%10.2f'%3900.00,'%10d'%0)
print('%-10s'%'0005','%-10s'%'热水器','%-10s'%'美的','%10.2f'%688.00,'%10d'%30)
print('%-10s'%'0006','%-10s'%'笔记本','%-10s'%'联想','%10.2f'%5699.00,'%10d'%10)
print('%-10s'%'0007','%-10s'%'微波炉','%-10s'%'苏泊尔','%10.2f'%480.50,'%10d'%33)
print('%-10s'%'0008','%-10s'%'投影仪','%-10s'%'松下','%10.2f'%1250.00,'%10d'%12)
print('%-10s'%'0009','%-10s'%'吸尘器','%-10s'%'飞利浦','%10.2f'%999.00,'%10d'%9)
print('----------------------------------------------')

#商品数据
products=[
    ['0001','电视机','海尔',5999.00,20],
    ['0002','冰箱','西门子',6998.00,15],
    ['0003','洗衣机','小天鹅',1999.00,10],
    ['0004','空调','格力',3900.00,0],
    ['0005','热水器','美的',688.00,30],
    ['0006','笔记本','联想',5699.00,10],
    ['0007','微波炉','苏泊尔',1250.00,12],
    ['0008','投影仪','松下',1250.00,12],
    ['0009','吸尘器','飞利浦',999.00,9],]


#用户输入信息
product_id=input('请输入您要购买的产品编号:')
count=int(input('请输入您要购买的产品数量:'))


#获取编号对应商品的信息
product_index=int(product_id)-1
product=products[product_index]



#计算金额
print('购买成功,您需要支付',product[3]*count,'元')


#退出系统
print('谢谢您的光临,下次再见')

 

task2-9-2源码

"""家用电器销售系统

v1.1
"""



#欢迎信息
print('欢迎使用家用电器销售系统')

#产品信息列表
print('产品和价格信息如下:')
print('**********************************************************')
print(f'{"编号":<10}{"名称":<10}{"品牌":<10}{"价格":<10}{"库存数量":<10}')
print('----------------------------------------------')
print(f'{"0001":<10}{"电视机":<10}{"海尔":<10}{5999.00:>10.2f}{20:>10d}')
print(f'{"0002":<10}{"冰箱":<10}{"西门子":<10}{6998.00:>10.2f}{15:>10d}')
print(f'{"0003":<10}{"洗衣机":<10}{"小天鹅":<10}{1999.00:>10.2f}{10:>10d}')
print(f'{"0004":<10}{"空调":<10}{"格力":<10}{3900.00:>10.2f}{0:>10d}')
print(f'{"0005":<10}{"热水器":<10}{"美的":<10}{688.00:>10.2f}{30:>10d}')
print(f'{"0006":<10}{"笔记本":<10}{"联想":<10}{5699.00:>10.2f}{10:>10d}')
print(f'{"0007":<10}{"微波炉":<10}{"苏泊尔":<10}{480.50:>10.2f}{33:>10d}')
print(f'{"0008":<10}{"投影仪":<10}{"松下":<10}{1250.00:>10.2f}{12:>10d}')
print(f'{"0009":<10}{"吸尘器":<10}{"飞利浦":<10}{999.00:>10.2f}{9:>10d}')
print('----------------------------------------------')

#商品数据
products=[
    ['0001','电视机','海尔',5999.00,20],
    ['0002','冰箱','西门子',6998.00,15],
    ['0003','洗衣机','小天鹅',1999.00,10],
    ['0004','空调','格力',3900.00,0],
    ['0005','热水器','美的',688.00,30],
    ['0006','笔记本','联想',5699.00,10],
    ['0007','微波炉','苏泊尔',1250.00,12],
    ['0008','投影仪','松下',1250.00,12],
    ['0009','吸尘器','飞利浦',999.00,9]]


#用户输入信息
product_id=input('请输入您要购买的产品编号:')
count=int(input('请输入您要购买的产品数量:'))


#获取编号对应商品的信息
product_index=int(product_id)-1
product=products[product_index]



#计算金额
print('购买成功,您需要支付',product[3]*count,'元')


#退出系统
print('谢谢您的光临,下次再见')

  

 

标签:%-,10.2,list,10d,实验,print,10s
From: https://www.cnblogs.com/prefectdown/p/17245180.html

相关文章

  • FPGA实验—— 流水灯
    FPGA实验流水灯时钟频率与时钟周期计算\[f=\frac{1}{T}\]f是频率T是周期时钟周期的计算1s=1000ms=1000000us=1000000000ns对于100kHz=100000Hzf=1000000000/1......
  • PPPOE实验
    静态IPR1配置dialer-ruledialer-rule10ippermitinterfaceDialer1link-protocolpppppppaplocal-userhcippasswordcipher123ipaddressppp-negotiate......
  • 实验2 字符串和列表
    实验任务1task.py实验源码:x='nbaFIFA'print(x.upper())print(x.lower())print(x.swapcase())print()x='abc'print(x.center(10,'*'))print(x.ljust(1......
  • 算法分析与设计——冒泡排序,选择排序,STL自带sort函数性能比较实验
    实验环境:Win11,Devc++5.11实验方法:生成不同数据量的随机数后使用三种排序方法分别排序,比较每种方法所耗时长。实验结果:数据量为1000时,冒泡排序平均用时为0.015s,选择排序平......
  • 实验2
    实验任务1task1源代码:x='nbaFIFA'print(x.upper())print(x.lower())print(x.swapcase())print()x='abc'print(x.center(10,'*'))print(x.ljust(10,'*'))......
  • DINO-DETR 实验与分析
    前言自DETR提出之后,不计其数的DETR改进模型不断被提出,尽管如此,基于Transformer模型的速度与精度却一直被人诟病。今天学习的这个DETR的改进模型,号称SOTA模型,这便是大名鼎鼎......
  • 实验2 字符串和列表
    实验二字符串和列表实验任务1task1.py实验源码x='nbaFIFA'print(x.upper())print(x.lower())print(x.swapcase())print()x='abc'print(x.center(10,'*'))......
  • 实验2 字符串和列表
    实验任务1task1.py实验源码:x='nbaFIFA'print(x.upper())print(x.lower())print(x.swapcase())print()x='abc'print(x.center(10,'*'))print(x.ljust(1......
  • 实验一 密码引擎-2-电子钥匙功能测试
    0参考附件中的视频1解压"资源"中“龙脉密码钥匙驱动实例工具等”压缩包2在Ubuntu中运行“龙脉密码钥匙驱动实例工具等\mToken-GM3000\skf\samples\linux_mac”中例程......
  • nfs实验步骤
    1.yuminstall-ynfs-utils查看是否安装nfs2.vim/etc/sysconfig/network-scripts/ifcfg-eno16777736编辑ip地址网关信息3.systemctlrestartnetwork重启网卡4.......