• PYTHON-模拟练习题目集合


     🌈write in front🌈
    🧸大家好,我是Aileen🧸.希望你看完之后,能对你有所帮助,不足请指正!共同学习交流.
    🆔本文由Aileen_0v0🧸 原创 CSDN首发🐒 如需转载还请通知⚠️
    📝个人主页:Aileen_0v0🧸—CSDN博客
    🎁欢迎各位→点赞👍 + 收藏⭐️ + 留言📝​
    📣系列专栏:Aileen_0v0🧸的PYTHON学习系列专栏——CSDN博客
    🗼我的格言:"没有罗马,那就自己创造罗马~"

    1. Which of the following expression is Illegal?

    O A.['12.56'] * 7
    O B. int(7.4)+7.4
    O C.['a','b','c']-['a']
    O D.str(1.32)*5

    考查:列表,整数,字符串的运算规则


    在Python中,列表的加法运算是将两个列表拼接成一个新的列表,例如:

    1. a = [1, 2, 3]
    2. b = [4, 5, 6]
    3. c = a + b # [1, 2, 3, 4, 5, 6]

    列表的乘法运算是重复一个列表多次得到一个新的列表,例如:

    1. a = [1, 2, 3]
    2. b = a * 3 # [1, 2, 3, 1, 2, 3, 1, 2, 3]

    列表不存在减法和除法运算。->选c

    2.Function defining

    Please define a function which can find out the all multiples of 3 (3的倍数) from 0 to nand return the sum of those mutiples.

    Header of the function:

    在这里描述函数接口。

    例如:def acc_three(n):
    n is larger than 3 and smaller than 1000

    1. def acc_three(n):
    2. sum = 0
    3. for i in range (3,n+1):
    4. if i % 3 == 0:
    5. sum += i
    6. return sum
    7. #👇为后台系统调用检查结果
    8. print(acc_three(1000))->166833

    考查函数相关的知识点,---> http://t.csdn.cn/TpC92

    3.Using Function Recursion(函数递归) to Find the Sum of 1-100

    1. def f(n):
    2. if n == 1: #递归结束条件
    3. return 1
    4. else:
    5. return n+f(n-1) #递归公式
    6. print(f(100))#5050

    考查函数递归知识点,-->http://t.csdn.cn/6uEc5

    4.Please read through the block carefully and finish the following tasks:Q1. output the average Python score of three students.Q2. Define a List to store the First name of all students.
    Remember to copy this code to your answer. All you need to do is to write your
    code under each condition below.

    1. student_dict = {
    2. "Kendrick Ray": {
    3. "Math": 60,
    4. "English": 45,
    5. "Python": 60
    6. },
    7. "Jhon Rick":{
    8. "Math": 90,
    9. "English": 95,
    10. "Python": 70
    11. },
    12. "Stephen Curry":{
    13. "Math": 80,
    14. "English": 90,
    15. "Python": 50
    16. }
    17. }
    18. sign = input()
    19. if sign == "avg":
    20. #
    21. py_sum = 0
    22. for stu in student_dict:
    23. py_sum = py_sum + student_dict[stu]["Python"]
    24. print(py_sum / 3)
    25. #
    26. elif sign == "name":
    27. #
    28. name_list =[] #创建一个空列表接收name
    29. for stu in student_dict: #遍历字典里面的字典
    30. stu_list = stu.split(" ")
    31. #使用split内置函数切割每个小字典的名字,并保存在新的列表stu_list中
    32. name_list.append(stu_list[0])
    33. #将新列表对应的name取出来储存在一个刚刚创建的空列表里
    34. print(name_list)
    35. #
    1. # Output prediction
    2. if 0:
    3. print("1")
    4. elif 1-1.0:
    5. print("2")
    6. else:
    7. print("3")

    结果:3

    1. z = -87.7e100
    2. print(type(z))
    3. #结果:float
    1. for x in range(28,31,3):
    2. print(x)
    3. # 28
    1. fruits = ["apple","banana","cherry"]
    2. for x in fruits:
    3. for y in x:
    4. if x == "banana":
    5. break
    6. print(y)
    7. #a
    8. #p
    9. #p
    10. #l
    11. #e
    12. #c
    13. #h
    14. #e
    15. #r
    16. #r
    17. #y

    上面两个for循环,x是取到列表里面的元素,y是取得元素的每个字母,虽然它break跳出了离他最近的内循环,但由于print的是y,所以能够取到 apple 和 cherry. 

    1. dict1 ={
    2. "brand": "Ford",
    3. "model": "Mustang",
    4. "year": 1964,
    5. "price": 20000
    6. }
    7. print(dict1["model"][4])
    8. print(len(dict1))
    9. #a
    10. #4

    🌈今天的练习就分享到这里啦~🌈

    🌈喜欢就一键三连支持一下吧~🌈

    🌈谢谢家人们!🌈

  • 相关阅读:
    越小越好: Q8-Chat,在英特尔至强 CPU 上体验高效的生成式 AI
    HW之轻量级内网资产探测漏洞扫描工具
    基于微信小程序的校园外卖平台设计与实现
    【实践篇】Redis最强Java客户端(三)之Redisson 7种分布式锁使用指南
    网站不被谷歌收录的常见原因及解决办法
    xml 解析bean工具类
    数据结构与算法——绪论
    linux虚拟机查看防火墙状态
    武汉新时标文化传媒有限公司抖音视频拍摄落地时的几个问题
    ‘HelloWorld‘ is declared but its value is never read.
  • 原文地址:https://blog.csdn.net/Aileenvov/article/details/132867133