Python Help, Basic Computer Science

Assignment Help:
I need help! import cgi, cgitb
cgitb.enable()

HTML_head = ''Content-type: text/html\n\n''
HTML_top = ''''''
Restaurant Results
''

Restaurant Results

''''''
HTML_bottom = ''''

HTML_table=''''''






''''''
Restaurant_filename = ''restaurant.txt''

MasterList = [] # master list of dictionaries

# -------------------------- Main -----------------------------
def Main():
global MasterList
lines = ReadData()
if lines == '''':
return CreateMasterList(lines)
form = cgi.FieldStorage()
group = ''''
if ''group'' in form:
group = form[''group''].value
if group == ‘checko’:
restaurant=''''
if ''restaurant'' in form:
restaurant= form[''restaurant''].value
Printchecko(restaurant)
elif group == ''subgroup'':
state=form[''group_borough''].value
cuisine=form[''Cuisine''].value
city=form[''cityyy’].value
number=form[''number''].value
print(state,cuisine,city,number)
elif group == ''total'':
state = form[''all_borough''].value
print state
else:
PrintError(''ERROR: Sorry. Restaurant is not an option.'')

# ------------------------- PrintError --------------------------
def PrintError(msg):
print HTML_head+HTML_top+''

''+msg+HTML_bottom

# ---------------------- ReadData --------------------------------
def readdata():
f=open(''restaurants.txt'',''r'')
s=f.read()
f.close()
y=s.replace(''Reserve Now'','''')
k=y.strip()
l=k.split(''\n'')
new=[]
x=0
while x if len(lines) < 2:
PrintError(''ERROR: Bad dataset in ''+ Restaurant_filename)
return ''''
elif:
new+=[l[x].split(''\t'')]
x+=1
return new
lines = lines[1:] # ignore column headers
return lines

# ------------------------- CreateMasterList -------------------
def CreateMasterList(lines):
global MasterList
for line in lines:
d = {}
fields = line.split('','')
if len(fields) >= 6:
if ''"'' in line:
words = line.split(''"'')
d[''name''] = words[1].strip()
else:
d[''name''] = fields[1].strip()
if fields[0] == ''s'':
d[''state'']=False
else:
d[''state'']=True
d[''city'']=(fields[-3])
d[''cuisine'']=(fields[-1])])
MasterList.append(d)

# ------------------------- PrintIndividual ---------------------
def Printchecko(restaurant):
lookfor = restaurant.strip().lower()
sortlist=[]
for d in MasterList:
if lookfor in d[''name''].lower():
d=Highlightrestaurant(d,lookfor)
sortlist.append([d[''name''].lower(),d])
sortlist.sort()
header=''Restaurant with names containing "''+ restaurant+''"''
PrintTable(header,sortlist)

# --------------------------- HighlightRestaurant-------------------
def HighlightRestaurant (d,lookfor):
front=''''
back=''
''
mixed=d[''name'']
low=mixed.lower()
ln=len(lookfor)
new_mixed=''''
while lookfor in low:
pos=low.find(lookfor)
new_mixed=mixed[:pos]+front+mixed[pos:pos+ln]+back
mixed=mixed[pos+ln:]
low=low[pos+ln:]
new_mixed+=mixed
d[''name-HTML'']=new_mixed
return d

# ------------------------ PrintTable ----------------------------
def PrintTable(header,sortedlist):
s=HTML_head+HTML_top
s+=''

''+header+''

''
s+=HTML_table
if len(sortedlist)==0:
s+=''''
for i in range(5):
s+=''''
else:
n=1
for i in range(5):
s+=''''
s+=''\n''
n+=1
s+=''
Restaurant nameStateCityCuisine
  No matches s
''
s+=HTML_bottom
print s
Main()

Related Discussions:- Python Help

Computer security, concepts and components of computer security

concepts and components of computer security

Choice of medium - transmission channels, Choice of Medium: All the tr...

Choice of Medium: All the transmission channels discussed in the foregoing paragraphs can be used as point to point connections or as broadcast systems. Transmitting informati

What is a tool bar?, Question 1 Write short notes on                      ...

Question 1 Write short notes on                           (a) Office Automatics System                           (b) Transaction Processing System Question 2 What is a too

Message quality and quantity, Message Quality and Quantity: Quality of...

Message Quality and Quantity: Quality of transmission is a very important .consideration in telecommunication. Voice communication can use a narrow bandwidth, which means the

Cprgm, A palindrome is a string that reads the same from both the ends. Giv...

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

Cryptography, Question 1 Consider the one-time pad encryption scheme to e...

Question 1 Consider the one-time pad encryption scheme to encrypt a 1-bit message m, and assume m is chosen with uniform distribution from message space M={0,1}. Let E1 be the ev

Microprocessor, what is computer? explaine the block diagram of a general p...

what is computer? explaine the block diagram of a general purpose digital computer.

Binary codes, Binary Codes: We have seen earlier that digital computer...

Binary Codes: We have seen earlier that digital computers use signals that have two distinct values and there exists a direct analogy between binary signals and binary digits.

Dbms, Explain displaying an er schema as an er diagram, Database Management...

Explain displaying an er schema as an er diagram, Database Management System

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd