当前位置:网站首页>[song] rebirth of me in py introductory training (7): function call
[song] rebirth of me in py introductory training (7): function call
2022-07-27 06:05:00 【Collapse an old face】
It's not easy to create , Before reference , Point a praise , Collection , You can't pay too much attention , Family
The first 1 Turn off : Built in functions - Tools that make you lazy
Programming requirements
The programming task of this pass is to complete src/Step2/prime.py File code , Realize corresponding functions . The specific requirements are as follows :
- Define a function , The function is to judge whether a number is a prime number ;
- Call function , Judge the input integer , If it is a prime number, the output is
True, If it is not a prime number, the output isFalse.# Please add code here , Judge the input integer , If it is a prime number, the output is True, If it is not a prime number, the output is False #********** Begin *********# def prime(self): if self==1: return False for i in range(2,n): if(n%i==0): return False break else: return True print(prime(n)) #********** End **********#The first 2 Turn off : The function correctly calls - Get the results you want
Task description
After the function is defined , It will not be executed automatically , Only after being called , Function will be executed , The corresponding results are obtained .
The goal of this chapter is to let readers understand and master the relevant knowledge of function call .
-------------------------------------------------------------------------------------------
Programming requirements
The programming task of this pass is to complete src/Step2/func_call.py File code , Realize corresponding functions . The specific requirements are as follows :
- Define a function , Sort the input value list from small to large ;
- Output sorted value list .
# Please add code here , Pair value list numbers Implement sorting from small to large
#********** Begin *********#
print(sorted(numbers))
#********** End **********#The first 3 Turn off : Functions and function calls - Distinguish between primary and secondary
Task description
We usually use the string 、 List and other variables as parameters for function calls . But the function itself is also an object , So we can also pass a function as a parameter into another function and call it .
The goal of this chapter is to let readers understand and master the relevant knowledge of function as a parameter passed into another function and called .
------------------------------------------------------------------
Programming requirements
The programming task of this pass is to complete src/step3/func_ref.py File code , Realize corresponding functions . The specific requirements are as follows :
- Define a function , It is required to calculate the area of the circle ;
- Radius according to different integer values entered , Call function calculation , The area of the output circle .
# Please add code here , Realize the area calculation of circle , And output area results #********** Begin *********# def area(n): return(PI*n*n) print("%.2f"% area(n)) #********** End **********#P.s: The code here should be correct , But I just can't pass the customs , After reference, reply to the solution in the boss comment area , Thank you guys
notes : The content is only for reference and sharing , Do not spread without permission , Tort made delete
边栏推荐
- 回调使用lambda
- [first song] rebirth of me in py introductory training (3): if conditional sentence
- 制作视频特效必备工具:NUKE 13
- 如何管理大量的定时任务
- Live Home 3D Pro室内家居设计工具
- 【头歌】重生之我在py入门实训中(4):循环程序
- 16. Over fitting and under fitting
- Weidongshan digital photo frame project learning (III) transplantation of freetype
- Cmder的基础文件操作
- 1. Introduction to pytorch
猜你喜欢
随机推荐
Day 2. Depressive symptoms, post-traumatic stress symptoms and suicide risk among graduate students
关于pytorch转onnx经常出现的问题
arcgis for js api(1) 获取featureLayer的所有字段名
2021-06-26
[first song] rebirth of me in py introductory training (4): Circular program
【Arduino】重生之Arduino 学僧(1)
图像超分辨率评价指标
malloc和new之间的不同-实战篇
Live Home 3D Pro室内家居设计工具
【头歌】重生之我在py入门实训中(12):Matplotlib接口和常用图形
关于pytorch反向传播的思考
模型的推理速度
维度问题以及等高线
Gbase 8C - SQL reference 6 SQL syntax (12)
Xmind 思维导图 2022 v12.0.3中文版更新了哪些内容?
13. Logistic regression
子类调用父类构造函数的时机
【12】理解电路:从电报机到门电路,我们如何做到“千里传信”?
VSCode解决运行ipynb文件使用卡顿问题
Can it replace PS's drawing software?









![[high concurrency] interviewer](/img/50/baa662cb4ce30cf2ef4cb5952960dd.jpg)