首页 > 其他分享 >实验二

实验二

时间:2023-03-31 19:24:21浏览次数:27  
标签:10 text len better 实验 print than

task1

 1 x="nba FIFA"
 2 print(x.upper())
 3 print(x.lower())
 4 print(x.swapcase())
 5 print()
 6 x="abc"
 7 print(x.center(10,'*'))
 8 print(x.ljust(10,'*'))
 9 print(x.rjust(10,'*'))
10 x="123"
11 print(x.zfill(10))
12 x=123
13 print(str(x).zfill(10))
14 print()
15 x="phone_number"
16 print(x.isidentifier())
17 x="222test"
18 print(x.isidentifier())
19 print()
20 x="  "
21 print(x.isspace())
22 x='\n'
23 print(x.isspace())
24 print()
25 x="python is fun"
26 table = x.maketrans("thon","1234")
27 print(x.translate(table))

 

task2

 1 x=[5,11,9,7,42]
 2 print('整数输出1:',end ='')
 3 i=0
 4 while i < len(x):
 5     print(x[i],end ='')
 6     i+=1
 7  
 8 print('\n整数输出2:',end = '')
 9 i = 0
10 while i <len(x):
11     print(f'{x[i]:02d}',end = '-')
12     i+=1
13  
14 print('\n整数输出3:', end = '')
15 i = 0
16 while i <len(x)-1:
17     print(f'{x[i]:02d}',end = '-')
18     i+=1
19 print(f'{x[-1]:02d}')
20  
21 print('\n字符输出1:',end = '' )
22 y1=[]
23 i=0
24 while i<len(x):
25     y1.append(str(x[i]))
26     i+=1
27 print('-'.join(y1))
28  
29 print('字符输出2:',end = '')
30 y2=[]
31 i=0
32 while i<len(x):
33     y2.append(str(x[i]).zfill(2))
34     i+=1
35 print('-'.join(y2))

 

task3

 1 name_list = ['david bowie','louis armstrong','leonard cohen','bob dylan','cocteau twins']
 2 i = 0
 3 while i < len(name_list):
 4     print(name_list[i].title())
 5     i+=1
 6  
 7 print()
 8  
 9 t=[]
10 i = 0
11 while i <len(name_list):
12     t.append(name_list[i].title())
13     i+=1
14  
15 print('\n'.join(t))

task4

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

task5

 1 import this
 2 text = ('''The Zen of Python, by Tim Peters
 3  
 4 Beautiful is better than ugly.
 5 Explicit is better than implicit.
 6 Simple is better than complex.
 7 Complex is better than complicated.
 8 Flat is better than nested.
 9 Sparse is better than dense.
10 Readability counts.
11 Special cases aren't special enough to break the rules.
12 Although practicality beats purity.
13 Errors should never pass silently.
14 Unless explicitly silenced.
15 In the face of ambiguity, refuse the temptation to guess.
16 There should be one-- and preferably only one --obvious way to do it.
17 Although that way may not be obvious at first unless you're Dutch.
18 Now is better than never.
19 Although never is often better than *right* now.
20 If the implementation is hard to explain, it's a bad idea.
21 If the implementation is easy to explain, it may be a good idea.
22 Namespaces are one honking great idea -- let's do more of those!''')
23 line = 0
24 word = 0
25 string = 0
26 space = 0
27 line = len(text.splitlines())
28 word = len(text.split())
29 string = len(text)
30 for i in text:
31     if i == " ":
32         space += 1
33 print('行数:{}'.format(line))
34 print('字数:{}'.format(word))
35 print('字符数:{}'.format(string))
36 print('空格数:{}'.format(space))

 

 


 

 

标签:10,text,len,better,实验,print,than
From: https://www.cnblogs.com/bhsyyds/p/17277264.html

相关文章

  • 实验三
    实验任务一程序源码:#include<stdio.h>#include<stdlib.h>#include<time.h>#include<windows.h>#defineN80voidprint_text(intline,intcol,chartext[]);//函数声明voidprint_spaces(intn);//函数声明voidprint_blank_lines(intn);//函数声明intmai......
  • 拼多多的三农新实验:向下扎根,向上入云
    技术能带来红利,也能扩大鸿沟。当ChatGPT引发人们对生产力大解放憧憬的同时,也带给人们担忧:哪些职业将受到冲击?是否会有更多人失业?事实上,每一轮重大技术革新中,都有行业、企业,甚至个体,因应用技术的时间先后、程度深浅不一,而拉开差距。幸运的是,总有一些人在努力磨平这种技术鸿沟。在......
  • 202031607332-阿卜杜热合曼·麦麦提艾萨 实验一 软件工程准备—对课程的初步认识
    项目内容班级博客链接2023年春软件工程(2020级计算机科学与技术本次作业要求链接实验一软件工程准备我的课程学习目标1.学习博客园软件开发者学习社区使用技巧和经验2.了解Github的基本操作本次作业在哪些方面帮我实现学习目标学习了博客园使用技巧,Github的......
  • 网络对抗实验四 恶意代码分析
    目录[实践内容](#1)(id="1")#实践内容(一)系统运行监控1.使用如计划任务,每隔一分钟记录自己的电脑有哪些程序在联网,连接的外部IP是哪里。运行一段时间并分析该文件,综述一下分析结果。目标就是找出所有连网的程序,连了哪里,大约干了什么(不抓包的情况下只能猜),你觉得它这么干合适不。......
  • 实验3
    实验任务1程序代码:#include<stdio.h>#include<stdlib.h>#include<time.h>#include<Windows.h>#defineN80voidprint_text(intline,intcol,chartext[]);//函数声明voidprint_spaces(intn);//函数声明voidprint_blank_lines(intn);//函数声明int......
  • 实验三
    task1.实验代码#include<stdio.h>#include<stdlib.h>#include<time.h>#include<windows.h>#defineN80voidprint_text(intline,intcol,chartext[]);//函数声明voidprint_spaces(intn);//函数声明voidprint_blank_lines(intn);......
  • 202031603210-李震 实验一软件工程准备-简单认识软件工程
    项目目标课程班级博客链接2020级卓越工程师班本次作业要求链接实验一软件工程准备我的课程学习目标1.学会使用博客园进行学习2.了解GitHub的基本操作3.学习并掌握软件工程的相关知识本次作业在哪些方面帮我实现学习目标通过本次实验,我学习了1.Git......
  • 实验三
    任务1:代码:#include<stdio.h>#include<stdlib.h>#include<time.h>#include<windows.h>#defineN80voidprint_text(intline,intcol,chartext[]);voidprint_spaces(intn);voidprint_blank_lines(intn);intmain(){intline......
  • 202031607130-杨国周 实验一 软件工程准备—初识软件工程
    实验一软件工程准备项目内容班级博客链接https://edu.cnblogs.com/campus/xbsf/2020CSSE本次作业要求链接https://edu.cnblogs.com/campus/xbsf/2020CSSE/homework/12938我的课程学习目标学习软件工程的基本概念、方法和工具,提高软件开发的质量和效率。本......
  • c实验3
     实验任务1#include<stdio.h>#include<stdlib.h>#include<time.h>#include<windows.h>#defineN80voidprint_text(intline,intcol,chartext[]);voidprint_spaces(intn);voidprint_blank_lines(intn);intmain(){intline,col,i......