现有一列表 ls = [‘the lord of the rings’,‘anaconda’,‘legally blonde’,‘gone with the wind’]

【问题描述】

现有一列表 ls = [‘the lord of the rings’,‘anaconda’,‘legally blonde’,‘gone with the wind’],编写程序,实现以下功能:‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

  1. 输入“1”,输出元素为0-9的3次方的列表‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

  2. 输入“2”,输出元素为0-9中偶数的3次方的列表‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

  3. 输入“3”,输出元素为元组的列表,元组中元素依次是0-9中的奇数和该数的3次方‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

  4. 输入“4”,将列表 ls 中每个元素首字母转为大写字母,输出新列表‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

  5. 输入其他字符,输出“End of the program”

【输入形式】
【输出形式】
【样例输入】
【样例输出】
【样例说明】
【评分标准】

n=eval(input())
if n==1:
    s=list(map(lambda x: x**3,range(0,10)))
    print(s)
elif n==2:
    l=[]
    for i in range(0,10):
        if i%2==0:
            l.append(i)  
    s=list(map(lambda x: x**3,l))
    print(s)
elif n==3:
    l=[]
    for i in range(0,10):
        if i%2==1:
            p=(i,i**3)
            l.append(p)  
    print(l)
elif n==4: 
    l=['the lord of the rings','anaconda','legally blonde','gone with the wind']
    s=list(map(lambda x:x.capitalize(),l))
    print(s)
else:
    print("End of the program")

【问题描述】

在两行中分别输入一个正整数M,N,输出这两个数的最大公约数和最小公倍数。
【输入形式】

在两行中分别输入一个正整数M,N
【输出形式】

在一行中依次输出M和N的最大公约数和最小公倍数,两数字间以1个空格分隔。
【样例输入】

4

6
【样例输出】

2 12
【样例说明】
【评分标准】

flag=False
p=100
while(flag==False):
    n=eval(input())
    if n==p:
        flag=True
    elif n<p:
        print("less than expected")
    elif n>p:
        print("larger than expected")
print("you win")

猜你喜欢

转载自blog.csdn.net/X131644/article/details/127271038
今日推荐