早教吧作业答案频道 -->英语-->
python3的问题,急啊classSpecialList:"""Alistthatcanholdalimitednumberofitems."""definit(self,size):"""(SpecialList,int)>>>L=SpecialList(10)>>>L.size10>>>L.valuelist[]
题目详情
python3的问题,急啊
class SpecialList:
"""A list that can hold a limited number of items."""
def __init__(self, size):
""" (SpecialList, int)
>>> L = SpecialList(10)
>>> L.size
10
>>> L.value_list
[]
"""
# complete this code
def push_value(self, new_value):
""" (SpecialList, object) -> NoneType
Append new_value to this list, if there is enough space in the list according to its maximum size.
If there is insufficient space, new_value should not be added to the list.
>>> L = SpecialList(10)
>>> L.push_value(3)
>>> L.value_list
[3]
"""
# complete this code
def pop_most_recent_value(self):
""" (SpecialList) -> object
Precondition: len(self.value_list) != 0
Return the value added most recently to value_list and remove it from the list.
>>> L = SpecialList(10)
>>> L.push_value(3)
>>> L.push_value(4)
>>> L.value_list
[3, 4]
>>> L.pop_most_recent_value()
4
"""
# complete this code
def compare(self, other):
""" (SpecialList, SpecialList) -> int
Return 0 if both SpecialList objects have lists of the same size.
Return 1 if self's list contains more items than other's list.
Return -1 if self's list contains fewer items than other's list.
"""
# complete this code
class SpecialList:
"""A list that can hold a limited number of items."""
def __init__(self, size):
""" (SpecialList, int)
>>> L = SpecialList(10)
>>> L.size
10
>>> L.value_list
[]
"""
# complete this code
def push_value(self, new_value):
""" (SpecialList, object) -> NoneType
Append new_value to this list, if there is enough space in the list according to its maximum size.
If there is insufficient space, new_value should not be added to the list.
>>> L = SpecialList(10)
>>> L.push_value(3)
>>> L.value_list
[3]
"""
# complete this code
def pop_most_recent_value(self):
""" (SpecialList) -> object
Precondition: len(self.value_list) != 0
Return the value added most recently to value_list and remove it from the list.
>>> L = SpecialList(10)
>>> L.push_value(3)
>>> L.push_value(4)
>>> L.value_list
[3, 4]
>>> L.pop_most_recent_value()
4
"""
# complete this code
def compare(self, other):
""" (SpecialList, SpecialList) -> int
Return 0 if both SpecialList objects have lists of the same size.
Return 1 if self's list contains more items than other's list.
Return -1 if self's list contains fewer items than other's list.
"""
# complete this code
▼优质解答
答案和解析
class SpecialList:
"""A list that can hold a limited number of items."""
def __init__(self, size):
""" (SpecialList, int)
>>> L = SpecialList(10)
>>> L.size
10
>>> L.value_list
[]
"""
self.size = size
self.value_list = []
def push_value(self, new_value):
""" (SpecialList, object) -> NoneType
Append new_value to this list, if there is enough space in the list according to its maximum size.
If there is insufficient space, new_value should not be added to the list.
>>> L = SpecialList(10)
>>> L.push_value(3)
>>> L.value_list
[3]
"""
self.value_list.append(new_value)
def pop_most_recent_value(self):
""" (SpecialList) -> object
Precondition: len(self.value_list) != 0
Return the value added most recently to value_list and remove it from the list.
>>> L = SpecialList(10)
>>> L.push_value(3)
>>> L.push_value(4)
>>> L.value_list
[3, 4]
>>> L.pop_most_recent_value()
4
"""
if not self.value_list:
return None
else:
return self.value_list.pop(-1)
def compare(self, other):
""" (SpecialList, SpecialList) -> int
Return 0 if both SpecialList objects have lists of the same size.
Return 1 if self's list contains more items than other's list.
Return -1 if self's list contains fewer items than other's list.
"""
self_vls = len(self.value_list)
oth_vls = len(other.value_list)
return (self_vls > oth_vls) - (self_vls < oth_vls)
"""A list that can hold a limited number of items."""
def __init__(self, size):
""" (SpecialList, int)
>>> L = SpecialList(10)
>>> L.size
10
>>> L.value_list
[]
"""
self.size = size
self.value_list = []
def push_value(self, new_value):
""" (SpecialList, object) -> NoneType
Append new_value to this list, if there is enough space in the list according to its maximum size.
If there is insufficient space, new_value should not be added to the list.
>>> L = SpecialList(10)
>>> L.push_value(3)
>>> L.value_list
[3]
"""
self.value_list.append(new_value)
def pop_most_recent_value(self):
""" (SpecialList) -> object
Precondition: len(self.value_list) != 0
Return the value added most recently to value_list and remove it from the list.
>>> L = SpecialList(10)
>>> L.push_value(3)
>>> L.push_value(4)
>>> L.value_list
[3, 4]
>>> L.pop_most_recent_value()
4
"""
if not self.value_list:
return None
else:
return self.value_list.pop(-1)
def compare(self, other):
""" (SpecialList, SpecialList) -> int
Return 0 if both SpecialList objects have lists of the same size.
Return 1 if self's list contains more items than other's list.
Return -1 if self's list contains fewer items than other's list.
"""
self_vls = len(self.value_list)
oth_vls = len(other.value_list)
return (self_vls > oth_vls) - (self_vls < oth_vls)
看了 python3的问题,急啊c...的网友还看了以下:
方程x^2/m-1+y^2/m=1表示一个椭圆……设命题P:方程x^2/m-1+y^2/m=1表示 2020-05-16 …
已知a>0,设命题p:函数y=a^x为减函数,命题q:当x[1/2,2]时,y=x+1/x>1/a 2020-05-17 …
1.命题p:“所有能被2整除的数都是偶数”的否定是?2.已知x,y属于R,且x加y等于3,则x/1 2020-06-06 …
设命题p:函数y=cos2x的最小正周期是π2命题q:函数y=sinx的图象关于y轴对称,则下列判 2020-07-15 …
概率论与数理统计题目求详解设X,Y为随机变量.已知P{X>=0,Y>=0}=2/5,P{X>=0} 2020-07-20 …
设命题p:a∈{y|y=-x2+2x+8,x∈R},命题q:关于x的方程x2+x-a=0有实根.( 2020-07-30 …
\已知命题p:若x>y,则-xy,则x2>y2,在命题①p∧q;②p∨q;③p∧(已知命题p:若x 2020-08-01 …
已知命题p:x>y>0,则-x<-y,q:若x>y,则x2>y2.在下列四个命题:p∧q,p∨q, 2020-08-01 …
命题q:y'=1-1/x^2,令y'=0,得x=1或-1(舍)怎么来的?已知a>0,设命题p:函数 2020-08-01 …
已知c>0设P:y=c^x在R上单调递增,Q:g(x)=ln(2cx^2-2x+1)的值域为R.若“ 2020-12-07 …