关于python里面的问题,python2.7,V.b)怎么写

关于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,怎么用?
xcf1123 1年前 已收到1个回答 举报

顾瞟一眼 幼苗

共回答了18个问题采纳率:100% 举报

声明一个全局变量x
下面是在函数中的使用,不用下面的方法,在函数内部(不用参数传递),再定义一个x,则x变量为局部变量.
global x
可以再函数内部,把变量声明成全局变量,重新绑定变量的值(就是可以重新赋值).当全局变量用.
global()[x]
可以再函数内部,取得全局变量的值.仅仅是读取值过来.

1年前

6
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 16 q. 0.400 s. - webmaster@yulucn.com