python期末题库

{1: 'Monday', 2: '星期二', 3: 'Wednesday', 4: 'Thusday', 5: 'Friday', 6: 'Saturday', 7: 'Sunday'}s=StringVar()#StringVar是Tk库内部定义的字符串变量类型,在这里用于管理部件上面的字符。Label(win,text='输入要翻译的内容:',width=15).place(x=15,y=10)Label(win,text='输入要翻译的内容:',width=15).place(x=15,y=10)
摘要由CSDN通过智能技术生成

题库

一、 简答题 (共33题,165分)

1、要求:一个内容为0,88,ac,ff,abc,ss的元组。

tuple=(0,88,"ac","ff","abc","ss")

2、删除元素ff

3、并在位置4添加新的元素h

4、返回新的元组。

(5.0)

正确答案:

解析:

2、1、创建一个列表:colors,内部元素为:red,yellow,blue,white,black,green,gray

2、在black前面插入一个元素:orange

3、把orange改为橙色。

4、在blue后面插入一个子表:[“pink”,”purple”]

5、返回white的索引值。

6、创建一个新列表11,22,33,44,并合并到colors中。

7、取出索引值4-8的所有元素。

8、取出最后2个元素。

9、使用循环,遍历列表所有元素,并输出元素值和对应的索引值。

10、删除gray元素。

(5.0)

正确答案:# 1、创建一个列表:colors,内部元素为:red,yellow,blue,white,black,green,gray

  colors = ['red','yellow','blue','white','black','green','gray']

  print('第一题:',colors)

# 2、在black前面插入一个元素:orange

  colors.insert(4,'orange')

  print('第二题:',colors)

# 3、把orange改为橙色。

  colors[4] = '橙色'

  print('第三题:',colors)

# 4、在blue后面插入一个子表:[“pink”,”purple”]

  list = ['pink','purple']

  colors.insert(3,list)

  print('第四题:',colors)

# 5、返回white的索引值。

  print('第五题:',colors.index('white'))

# 6、创建一个新列表11,22,33,44,并合并到colors中。

  newlist= [11,22,33,44,]

  print('第六题:',colors + nub)

# 7、取出索引值4-8的所有元素。

  print('第七题:',colors[4:8])

# 8、取出最后2个元素。

  print('第八题:',colors[-2:])

# 9、使用循环,遍历列表所有元素,并输出元素值和对应的索引值。

  for i in colors:

    print('第九题:','元素值是:',i,'索引值是:',colors.index(i))

#10、删除gray元素。

  # del colors[8]            # 方法1

  # colors.pop(8)            # 方法2

  colors.remove("gray")      # 方法3

#11、删除colors。

  del colors

解析:

3、 使用列表推导式生成一个存放1-100中个位数为3的数据列表。

(5.0)

正确答案: result = [x for x in range(3, 101, 10)]

print(result)

解析:

4、补充下列代码,实现输入一个8位数表示的年月日,读出月份数字并输出该月有多少天。

def is_leap(year):

    """判断year是否为闰年,闰年返回True,非闰年返回False"""

##### 

def days_of_month(date_str):

    """根据输入的年月日,返回该月的天数"""

#####

    date_in = input()  # 输入一个年月日

    print(days_of_month(date_in))

(5.0)

正确答案:

解析:

5、使用递归法计算自然数各位数字之和。

比如:输入151,经递归函数计算后输出1+5+1计算结果:7

通常要获得数字的最后一位数,可以取模:

last= n % 10

该数字的其余部分(不包括最后一个地方)是:

rest = n // 10

(5.0)

正确答案:def func(num):

    if num < 10:

        return num

    else:

        return func(num // 10) + func(num % 10)

num = int(input("请输入任意数字: "))

res = func(num)

print(res)

解析:

6、使用map()函数计算自然数各位数字之和。

(5.0)

正确答案:

n=input()

l=list(map(int,n))

print(sum(l))

解析:

7、使用三种方法调用math库中的pow(底数,指数)函数,计算2的100次方。

&

  • 2
    点赞
  • 51
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值