当前位置:网站首页>【头歌】重生之我在py入门实训中(6):函数的定义与应用
【头歌】重生之我在py入门实训中(6):函数的定义与应用
2022-07-27 05:19:00 【垮起个老脸】
创作不易,参考之前,点个赞,收藏,关注一下不过分吧,家人们
第1关:十进制数转换为二进制数
任务描述
本关任务:编写函数,接收一个十进制整数为参数,返回等值的二进制数。
--------------------------------------------------------------------------
编程要求
根据提示,在右侧编辑器补充代码,输出十进制整数的对应二进制数。
def dec_to_bin( number ):
#********** Begin *********/
# 在此处补全代码
binnum = bin(number)
return binnum[2:]
#********** End **********/
num = int(input())第2关:数字排序
任务描述
本关任务:编写一个程序,输入4个整数,要求按由小到大的顺序输出
----------------------------------------------------------
编程要求
根据提示,在右侧编辑器补充代码,按由小到大的顺序输出4个整数。
def sort( l ):
#********** Begin *********/
#在此处补全代码
l.sort()
return l
#********** End **********/
line = input()第3关:杨辉三角
任务描述
本关任务:编写函数,接收一个整数n为参数,打印杨辉三角前n行。
-------------------------------------------------------------
编程要求
根据提示,在右侧编辑器补充代码,输出杨辉三角。
# -*- coding:utf-8 -*-
def yanghui(n):
#********** Begin *********/
#在此处补全代码
if n==0:
return []
if n==1:
return [[1]]
if n==2:
return [[1],[1,1]]
n -= 2
rList = [[1],[1,1]]
while n>0:
newList = [1]
for i in range(len(rList[-1])-1):
newList.append(rList[-1][i]+rList[-1][i+1])
newList.append(1)
rList.append(newList)
n -= 1
return rList
#********** End **********/
注:内容只做参考和分享,未经允许不可传播,侵权立删
边栏推荐
- Public opinion & spatio-temporal analysis of infectious diseases literature reading notes
- pytorch转onnx相关问题
- 5. Indexing and slicing
- Digital image processing Chapter 5 - image restoration and reconstruction
- 6. Dimension transformation and broadcasting
- Emoji表情符号用于文本情感分析-Improving sentiment analysis accuracy with emoji embedding
- 10. Gradient, activation function and loss
- Cap principle
- Gbase 8C - SQL reference 4 character set support
- Digital image processing Chapter 2 fundamentals of digital image
猜你喜欢

11.感知机的梯度推导

15. GPU acceleration, Minist test practice and visdom visualization

数字图像处理 第八章——图像压缩

【并发编程系列9】阻塞队列之PriorityBlockingQueue,DelayQueue原理分析

【mysql学习】8

9. High order operation

Digital image processing Chapter 8 - image compression

新冠时空分析——Global evidence of expressed sentiment alterations during the COVID-19 pandemic

DSGAN退化网络

数字图像处理第五章——图像复原与重建
随机推荐
5.索引和切片
Gbase 8C - SQL reference 4 character set support
Day 8.Developing Simplified Chinese Psychological Linguistic Analysis Dictionary for Microblog
一张照片攻破人脸识别系统:能点头摇头张嘴,网友
【Unity URP】代码获取当前URP配置UniversalRendererData,并动态添加RendererFeature
System Design的相关准备材料
Day 2. Depressive symptoms, post-traumatic stress symptoms and suicide risk among graduate students
10.梯度、激活函数和loss
SoK: The Faults in our ASRs: An Overview of Attacks against Automatic Speech Recognition (题目过长)阅读笔记
西瓜书学习笔记---第一、二章
Day 4.Social Data Sentiment Analysis: Detection of Adolescent Depression Signals
A photo breaks through the face recognition system: you can nod your head and open your mouth, netizens
数字图像处理——第九章 形态学图像处理
8. Mathematical operation and attribute statistics
11. Gradient derivation of perceptron
【高并发】面试官
GBASE 8C——SQL参考6 sql语法(12)
5. Indexing and slicing
关于pytorch反向传播的思考
子类调用父类构造函数的时机