Closed

PYTHON HOMEWORK!!!

This project received 20 bids from talented freelancers with an average bid price of $105 USD.

Get free quotes for a project like this
Employer working
Project Budget
N/A
Total Bids
20
Project Description

CLICK HERE [url removed, login to view]

SLP assignment: your assignment is about classes & methods, inheritance,input/output, linked lists, and improve the program questor.

Require

Read chapter 17 and 18 from “Think Python: How to Think Like a Computer Scientist (Version 1.3.3)”, a reference in the background materials. Code all the examples and exercises except [url removed, login to view] & [url removed, login to view] in Python and successfully run them.

Read chapter 12 from A Byte of Python, a reference in the background materials. Code all the examples and exercises in Python IDE and successfully run them.

Read chapter 17 from “How to Think Like a Computer Scientist Learning with Python (1st Edition)”, a reference in the background materials. Code all the examples in Python and successfully run them.

Find a way to improve the program below to save the input data and load it back in so that the program doesn't get amnesia every time you quit. Run and debug your improved program.

This is a Python program which has a class and other features. In this script, you think of an item, and the computer tries to guess it. When it is wrong, you teach it about your new item. After a few dozen games, it starts to get pretty smart!

# [url removed, login to view]

# define some constants for future use

kQuestion = 'question'

kGuess = 'guess'

# define a function for asking yes/no questions

def yesno(prompt):

ans = raw_input(prompt)

return (ans[0]=='y' or ans[0]=='Y')

# define a node in the question tree (either question or guess)

class Qnode:

# initialization method

def __init__(self,guess):

[url removed, login to view] = kGuess

[url removed, login to view] = guess

# get the question to ask

def query(self):

if ([url removed, login to view] == kQuestion):

return [url removed, login to view] + " "

elif ([url removed, login to view] == kGuess):

return "Is it a " + [url removed, login to view] + "? "

else:

return "Error: invalid node type!"

# return new node, given a boolean response

def nextnode(self,answer):

return [url removed, login to view][answer]

# turn a guess node into a question node and add new item

# give a question, the new item, and the answer for that item

def makeQuest( self, question, newitem, newanswer ):

# create new nodes for the new answer and old answer

newAnsNode = Qnode(newitem)

oldAnsNode = Qnode([url removed, login to view])

# turn this node into a question node

[url removed, login to view] = kQuestion

[url removed, login to view] = question

# assign the yes and no nodes appropriately

[url removed, login to view] = {newanswer:newAnsNode, not newanswer:oldAnsNode}

def traverse(fromNode):

# ask the question

yes = yesno( [url removed, login to view]() )

# if this is a guess node, then did we get it right?

if ([url removed, login to view] == kGuess):

if (yes):

print "I'm a genius!!!"

return

# if we didn't get it right, return the node

return fromNode

# if it's a question node, then ask another question

return traverse( [url removed, login to view](yes) )

def run():

# start with a single guess node

topNode = Qnode('python')

done = 0

while not done:

# ask questions till we get to the end

result = traverse( topNode )

# if result is a node, we need to add a question

if (result):

item = raw_input("OK, what were you thinking of? ")

print "Enter a question that distinguishes a",

print item, "from a", [url removed, login to view] + ":"

q = raw_input()

ans = yesno("What is the answer for " + item + "? ")

[url removed, login to view]( q, item, ans )

print "Got it."

# repeat until done

print

done = not yesno("Do another? ")

print

# immediate-mode commands, for drag-and-drop or execfile() execution

if __name__ == '__main__':

run()

print

raw_input("press Return>")

else:

print "Module questor imported."

print "To run, type: [url removed, login to view]()"

print "To reload after changes to the source, type: reload(questor)"

# end of [url removed, login to view]

Add the Python files from all 3 requirements above to one zip file. Add a one page write-up of your results and experiences to the zip file.

SLP assignment expectations:

Implement the code required for all the above 3 requirements.

Write a one page description of your results and experiences.

Skills Required

Looking to make some money?

  • Set your budget and the timeframe
  • Outline your proposal
  • Get paid for your work

Hire Freelancers who also bid on this project

    • Forbes
    • The New York Times
    • Time
    • Wall Street Journal
    • Times Online