首页 > 其他分享 >实验2

实验2

时间:2023-03-22 11:45:42浏览次数:27  
标签:name list len better 实验 print than

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,'*'))
print()

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

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))

task3

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))

task4

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

task5

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!'''
print('行数:',len(str.splitlines(x)))
print('单词数:', len(str.split(x)))
print('字符数:')
print('空格数:')

 

标签:name,list,len,better,实验,print,than
From: https://www.cnblogs.com/heqifan666/p/17243174.html

相关文章

  • 实验二
    task1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;sra......
  • 实验2
    实验任务1  问题一:line18将几个随机数组合起来问题二:根据当时的电脑时间,随机生成四个四位数 实验任务2 #include<stdio.h>#include<stdlib.h>intmain()......
  • 实验2
    TASK1//程序作用:随机生成五个学号#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnu......
  • 实验二
    实验任务1程序源码:#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;......
  • 实验二
      实验任务1task1.c#include<stdio.h>#include<stdlib.h>#include<time.h>#defineR2701#defineN5#defineR1586intmain(){ intnumber; int......
  • 实验2
    实验一程序源码:#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;......
  • 跟着字节AB工具DataTester,5步开启一个实验
    更多技术交流、求职机会,欢迎关注字节跳动数据平台微信公众号,回复【1】进入官方交流群 火山引擎A/B测试平台DataTester孵化于字节跳动业务内部,在字节跳动,“万事皆A/B,一切可......
  • 跟着字节AB工具DataTester,5步开启一个实验
    更多技术交流、求职机会,欢迎关注字节跳动数据平台微信公众号,回复【1】进入官方交流群 火山引擎A/B测试平台DataTester孵化于字节跳动业务内部,在字节跳动,“万事皆A/B,......
  • 实验二
    试验任务一 程序源码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;i......
  • 实验一 密码引擎-1-OpenEuler-OpenSSL编译
    实验一密码引擎-1-OpenEuler-OpenSSL编译0.安装Ubuntu和OpenEuler虚拟机1.下载最新的OpenSSL源码(1.1版本)2.用自己的8位学号建立一个文件夹,cd你的学号,用pwd获得绝......