早教吧作业答案频道 -->英语-->
关于python里面的问题,python2.7,V.b)怎么写IV.MakingsurestudentsareniceTheinstructoralwayshastomakesurethatstudentsbehavewell,andparticularlythattheydon’tcheat.Thesimplestwaytocheckwhetherstudentscouldbecheatingi
题目详情
关于python里面的问题,python2.7,V.b)怎么写
IV.Making sure students are nice
The instructor always has to make sure that students behave well,and particularly that they don’t
cheat.The simplest way to check whether students could be cheating is when they get the same grade
on the assignment.You will write a function that takes as argument a list of grades.The function will
return “check!” when at least two grades are identical,and “ok” otherwise.For example,with the list
[3,6,5.5,2,6] we would see “check!”,and with [4,2,6,5] we would see “ok”.
a) Write a function cheatingSort that first sorts the list and then checks for identical grades by
using the fact that the list is sorted.
b) Write a function cheatingNoSort that solves the problem without sorting the list.
V.We must dispose of evil students
a) The instructor is very sad when he finds out that some students cheated on assignments.After
he hangs them,he needs a function removeEvilStudents that takes two arguments:a list of
grades,and the grade of the students who cheated.The function removes that grade from the
whole list,and returns the list.For example,[3,6,5.5,2,6] gets returned as [3,5.5,2].
b) Write a function howManyGroupsCouldCheat that takes a list of grades and returns how many
grades are identical.That function must use cheatingNoSort and removeEvilStudents.For
example,for the list [0,3,4,3,0,5] there are 2 identical grades:0 and 3 are repeated.
老师跟我说要用global,怎么用?
IV.Making sure students are nice
The instructor always has to make sure that students behave well,and particularly that they don’t
cheat.The simplest way to check whether students could be cheating is when they get the same grade
on the assignment.You will write a function that takes as argument a list of grades.The function will
return “check!” when at least two grades are identical,and “ok” otherwise.For example,with the list
[3,6,5.5,2,6] we would see “check!”,and with [4,2,6,5] we would see “ok”.
a) Write a function cheatingSort that first sorts the list and then checks for identical grades by
using the fact that the list is sorted.
b) Write a function cheatingNoSort that solves the problem without sorting the list.
V.We must dispose of evil students
a) The instructor is very sad when he finds out that some students cheated on assignments.After
he hangs them,he needs a function removeEvilStudents that takes two arguments:a list of
grades,and the grade of the students who cheated.The function removes that grade from the
whole list,and returns the list.For example,[3,6,5.5,2,6] gets returned as [3,5.5,2].
b) Write a function howManyGroupsCouldCheat that takes a list of grades and returns how many
grades are identical.That function must use cheatingNoSort and removeEvilStudents.For
example,for the list [0,3,4,3,0,5] there are 2 identical grades:0 and 3 are repeated.
老师跟我说要用global,怎么用?
▼优质解答
答案和解析
声明一个全局变量x
下面是在函数中的使用,不用下面的方法,在函数内部(不用参数传递),再定义一个x,则x变量为局部变量.
global x
可以再函数内部,把变量声明成全局变量,重新绑定变量的值(就是可以重新赋值).当全局变量用.
global()[x]
可以再函数内部,取得全局变量的值.仅仅是读取值过来.
下面是在函数中的使用,不用下面的方法,在函数内部(不用参数传递),再定义一个x,则x变量为局部变量.
global x
可以再函数内部,把变量声明成全局变量,重新绑定变量的值(就是可以重新赋值).当全局变量用.
global()[x]
可以再函数内部,取得全局变量的值.仅仅是读取值过来.
看了 关于python里面的问题,...的网友还看了以下:
有相等表面积的球和正方体,它们的体积记为V球和V正,球的直径为d,正方体的棱长为a,则它们的大小关 2020-05-15 …
谁能把我把这些公式弄成手写公式s(t)=at^2/2+v(0)t=(v(t)^2-v(0)^2)/ 2020-05-16 …
v=kx的V-T图像一质点由静止开始沿直线运动,运动的速度大小为v,位移大小为x,v与x存在如下关 2020-06-19 …
已知Fe3+与I-在水溶液中发生:2I-+2Fe3+=2Fe2++I2.该反应正反应速率和I-、F 2020-07-09 …
数据结构题14.若一个栈以向量V[1..n]存储,初始栈顶指针top为n+1,则下面x进栈的正确操 2020-07-10 …
multiplydefinedsymbolsfound#includemain(){doublea 2020-07-23 …
一道数学题:设O是直线AB外一点,向量OA=向量A.向量OB=向量B,点A1,A2……An-1是线 2020-08-01 …
一种放铅笔的V形槽从下往上数,第一层放一只,第二层放两只,以此类推只要数一数顶层的只数n,就可以算出 2020-11-10 …
关于浮力的推算问题教科书上写“当P液大于P物时,有P液gV排大于P物gV物,即F浮大于G物,物体会上 2020-11-16 …
宝石排列问题N等于4时,输出的测试结果是多少?现有n种不同形状的宝石,每种n颗,共n*n颗。同一种形 2020-12-24 …