View the step-by-step solution to:

The assignment require us to change this two file into generator type, (the requirement is in to image I unload) but I simply don't understand the

The assignment require us to change this two file into generator type, (the requirement is in to image I unload)  but I simply don't understand the concept because there's no example for me to look at.

Background image of page 1
# -*- coding: utf-8 -*- """ Created on Tue Apr 26 21:42:51 2016 @author: Jesse """ import string class CharCounter(object): def __init__(self, filename, length): self.filename = filename self.length = length self.word = "" self.list_file = [] file = open(self.filename) for line in file: for w in line.split(): w = str(w).rstrip().strip(string.punctuation) if(len(w)==self.length): self.list_file.append(w) file.close() self.current = 0 self.size = len(self.list_file) def __iter__(self): return self def next(self): if(self.current == self.size): raise StopIteration else: self.word=self.list_file[self.current] self.current += 1 return self.word if __name__ == "__main__": for word in CharCounter ('agency.txt', 11): print ('%s' % word)
Background image of page 1
# -*- coding: utf-8 -*- """ Created on Tue Apr 26 21:41:15 2016 @author: Jesse """ class Question(object): def __init__(self): self.ques=None self.ans=None self.user_ans=None def setText(self, ques): self.ques=ques def setAnswer(self, ans): self.ans=ans def display(self): print self.ques def checkAnswer(self, user_ans): self.user_ans = user_ans if self.user_ans == self.ans: print 'Correct!' else: print 'Incorrent!' class ChoiceQuestion(Question): def __init__(self): super(ChoiceQuestion, self).__init__ self.ans={} def addChoice(self,choice,boo): self.ans[choice]=boo return self.ans def display(self): print self.ques i=1 for k,v in self.ans.iteritems(): print "%i:%s" %(i,k) i+=1 def checkAnswer(self,num): num=int(num) att=self.ans.values()[num-1] if att == True: print 'Correct!' else: print 'Incorrent!' def presentQuestion(Question): for i in Question: i.display() answer=raw_input('Please enter the answer for the problem:') i.checkAnswer(answer)
Background image of page 1
Sign up to view the entire interaction

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question