现有一列表 ls = ['the lord of the rings','anaconda','legally blonde','gone with the wind'],编写程序,实现以下功能:
输入“1”,输出元素为0-9的3次方的列表
输入“2”,输出元素为0-9中偶数的3次方的列表
输入“3”,输出元素为元组的列表,元组中元素依次是0-9中的奇数和该数的3次方
输入“4”,将列表 ls 中每个元素首字母转为大写字母,输出新列表
输入其他字符,输出“End of the program”
ls = ['the lord of the rings','anaconda','legally blonde','gone with the wind']
num = input('num: ')
if num == '1':
print([_ ** 3 for _ in range(10)])
elif num == '2':
print([_ ** 3 for _ in range(10) if not _ % 2])
elif num == '3':
print([(_, _ ** 3) for _ in range(10) if _ % 2])
elif num == '4':
print([_.title() for _ in ls])
else:
print('End of the program')
ls = ['The lord of the rings','Anaconda','Legally blonde','Gone with the wind']
list1 = []
list2 = []
list3 = []
n = (input())
if n == "1":
for i in range(10):
item = pow(i,3)
list1.append(item)
print(list1)
elif n == "2":
for i in range(0,10,2):
list2.append((pow(i,3)))
print(list2)
elif n == "3":
for i in range(1,10,2):
list3.append((i,pow(i,3)))
print(list3)
elif n == "4":
' '.join(ls).title().split()
print(ls)
else:
print("End of the program")