所以我有这个问题,它说创建一个类队列并使该方法出列并入队
这就是我到目前为止,有人能引导我走上正轨吗?
class queue:
def __init__(self,queue):
self.queue = []
def dequeue(self):
if len(queue) > 0:
e = queue[0]
queue = list[1:len(queue)]
else:
return "There are no elements to remove"
def enqueue(self,element):
queue.insert([-1], element)
Run Code Online (Sandbox Code Playgroud) import os
import random
os.chdir("C:\Users\Mainuser\Desktop\Lab6")
#Am i supposed to have a os.chdir?
# I think this is what's giving the error
#how do i fix this?
def getDictionary():
result = []
f = open("pocket-dic.txt","r")
for line in f:
result = result + [ line.strip() ];
return result
def makeText(dict, words=50):
length = len(dict)
for i in range(words):
num = random.randrange(0,length)
words = dict[num]
print word,
if (i+1) % 7 == 0:
print
Run Code Online (Sandbox Code Playgroud)
Python给我一个错误,说它无法找到指定的路径,当我在桌面上清楚地有一个带有该名称的文件夹时.它可能是os.chidr ?? 我究竟做错了什么?
def binary_search(li, targetValue):
low, high = 0, len[li] #error on this line
while low <= high:
mid = (high - low)/2
if li[mid] == targetValue:
return "we found it!"
elif li[mid] > targetValue:
low = mid - 1;
elif li[mid] < targetValue:
high = mid + 1;
print "search failure "
Run Code Online (Sandbox Code Playgroud)
刚刚发布了这个问题,但我的代码仍然不起作用?
甚至问这个我感到很尴尬,但是因为某种原因python让我的错误给了我"l"
def binary_search(l, targetValue):
low = 0, high = len(array)
while low <= high:
mid = (high - low)/2
if l[mid] == targetValue:
return "we found it!"
elif l[mid] > targetValue:
low = mid - 1;
else l[mid] < targetValue: #this line seems to be the problem
high = mid + 1;
print "search failure :( "
Run Code Online (Sandbox Code Playgroud)