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中,列表的加法运算是将两个列表拼接成一个新的列表,例如:

python 复制代码
a = [1, 2, 3]
b = [4, 5, 6]
c = a + b # [1, 2, 3, 4, 5, 6]

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

python 复制代码
a = [1, 2, 3]
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

python 复制代码
def acc_three(n):
    sum = 0
    for i in range (3,n+1):
        if i % 3 == 0:
            sum += i
    return sum

#👇为后台系统调用检查结果
print(acc_three(1000))->166833

考查函数相关的知识点 ,---> http://t.csdn.cn/TpC92
3.Using Function Recursion(函数递归) to Find the Sum of 1-100

python 复制代码
def f(n):
    if n == 1: #递归结束条件
        return 1
    else:
        return n+f(n-1) #递归公式

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.

python 复制代码
student_dict = {
    "Kendrick Ray": {
        "Math": 60,
        "English": 45,
        "Python": 60
    },
    "Jhon Rick":{
          "Math": 90,
        "English": 95,
        "Python": 70
    },
    "Stephen Curry":{
          "Math": 80,
        "English": 90,
        "Python": 50
    }
}
sign = input()

if sign == "avg":
#
    py_sum = 0
    for stu in student_dict:
        py_sum = py_sum + student_dict[stu]["Python"]
    print(py_sum / 3)
#

elif sign == "name":
#
    name_list =[]    #创建一个空列表接收name
    for stu in student_dict:    #遍历字典里面的字典
        stu_list = stu.split(" ")    
#使用split内置函数切割每个小字典的名字,并保存在新的列表stu_list中

        name_list.append(stu_list[0])    
#将新列表对应的name取出来储存在一个刚刚创建的空列表里
    print(name_list)
#
python 复制代码
# Output prediction
if 0:
    print("1")
elif 1-1.0:
    print("2")
else:
    print("3")

结果:3

python 复制代码
z = -87.7e100
print(type(z))
#结果:float
python 复制代码
for x in range(28,31,3):
    print(x)
# 28
python 复制代码
fruits = ["apple","banana","cherry"]
for x in  fruits:
    for y in  x:
        if x == "banana":
            break
        print(y)

#a
#p
#p
#l
#e
#c
#h
#e
#r
#r
#y

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

python 复制代码
dict1 ={
"brand": "Ford",
"model": "Mustang",
"year":  1964,
"price": 20000
}
print(dict1["model"][4])
print(len(dict1))
#a
#4

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

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

🌈谢谢家人们!🌈

相关推荐
крон3 小时前
【Auto.js例程】华为备忘录导出到其他手机
开发语言·javascript·智能手机
zh_xuan3 小时前
c++ 单例模式
开发语言·c++·单例模式
老胖闲聊4 小时前
Python Copilot【代码辅助工具】 简介
开发语言·python·copilot
Blossom.1184 小时前
使用Python和Scikit-Learn实现机器学习模型调优
开发语言·人工智能·python·深度学习·目标检测·机器学习·scikit-learn
曹勖之4 小时前
基于ROS2,撰写python脚本,根据给定的舵-桨动力学模型实现动力学更新
开发语言·python·机器人·ros2
豆沙沙包?5 小时前
2025年- H77-Lc185--45.跳跃游戏II(贪心)--Java版
java·开发语言·游戏
军训猫猫头5 小时前
96.如何使用C#实现串口发送? C#例子
开发语言·c#
lyaihao5 小时前
使用python实现奔跑的线条效果
python·绘图
恰薯条的屑海鸥5 小时前
零基础在实践中学习网络安全-皮卡丘靶场(第十六期-SSRF模块)
数据库·学习·安全·web安全·渗透测试·网络安全学习
liuyang-neu5 小时前
java内存模型JMM
java·开发语言