Question

Create a class called ASCIIDecoder this class should: A. Be an iterable object _iter_) B. Be an iterator _next_) Since it is an iterator of itself, the_iter__call should just initialize any variables used for iteration and return self. Functionally the ASCII decoder is initialized with a string and when iterated returns the ordinal (numeric) value for one character at a time...chr) and ord) are functions that can convert to and from ASCIl values. # Test Code: ad ASCIIDecoder (C-3PO:hi) for n in ad: print (n,end-: ) print (\n ) # should be able to reset when iterating a second time for n in ad: print (n, end-,) # # # OUTPUT: 67:45:51:80:79:58:104:105: 67,45,51,80,79,58,|04,105,

Using Python 3.x to solve this problem

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:--                                                      Date:--02/11/2018

class ASCIIDecoder:

        def __init__(self, text):

                self._text = text

                self._current = 0;

        def __iter__(self):

                self._current = 0;

                return self

        def __next__(self):

                if self._current >= len(self._text):

                        raise StopIteration

                else:

                        self._current += 1

                return ord(self._text[self._current - 1])

ad = ASCIIDecoder('C-3PO:hi')

for n in ad:

      print(n, end=':')

print('\n---')

for n in ad:

        print(n, end=',')

Output:--

67:45:51:80:79:58:104:105 67,45, 51,80, 79, 58,104,105,

Add a comment
Know the answer?
Add Answer to:
Using Python 3.x to solve this problem Create a class called ASCIIDecoder this class should: A....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please can I have a UML Class diagram for the Python program below: def main(): print()...

    Please can I have a UML Class diagram for the Python program below: def main(): print() print("Welcome to Caesar Encryption and Viginere Decryption Cipher") print() print("Please select an option") option = "c" while option == "c": hello = input('Choose Caesar Cipher encrypt 1:\n' 'Choose Viginere Cipher Decrypt 2:\n') message = input('Enter a message: ') password = input('Enter a password: ') if hello == '1': viginere_cipher(message, password) elif hello == '2': viginere_cipher_decrypt(message, password) print() print("Choose an option") option = input('Enter c...

  • Create a program using the Random class and While loops in Java. The program should generate...

    Create a program using the Random class and While loops in Java. The program should generate a random number from 50 through 100. The loop should add the five random numbers generated. On each iteration of the loop the program should print out the number generated, how many numbers have been generated thus far, and the sum so far. On the last iteration, the printout should say the The final total is.... Teach comment the last time I did it:...

  • python 3 inheritance Define a class named bidict (bidirectional dict) derived from the dict class; in...

    python 3 inheritance Define a class named bidict (bidirectional dict) derived from the dict class; in addition to being a regular dictionary (using inheritance), it also defines an auxiliary/attribute dictionary that uses the bidict’s values as keys, associated to a set of the bidict’s keys (the keys associated with that value). Remember that multiple keys can associate to the same value, which is why we use a set: since keys are hashable (hashable = immutable) we can store them in...

  • Use sorting techniques in the language Python 3 Devise an algorithm and implement it in a program to solve the following problem, similar to one often faced by an MP3 player. For our purposes, a song...

    Use sorting techniques in the language Python 3 Devise an algorithm and implement it in a program to solve the following problem, similar to one often faced by an MP3 player. For our purposes, a song consists of the following data fields: title (a nonempty ASCII string) composer (a (possibly empty) ASCII string), running time (a positive integer). Input consists of n songs and an integer k with 1 Sksn. Your program must find the k songs with longest running...

  • PYTHON 3 Object Oriented Programming ***a9q3.py file below*** class GradeItem(object): # A Grade Item is anything...

    PYTHON 3 Object Oriented Programming ***a9q3.py file below*** class GradeItem(object): # A Grade Item is anything a course uses in a grading scheme, # like a test or an assignment. It has a score, which is assessed by # an instructor, and a maximum value, set by the instructor, and a weight, # which defines how much the item counts towards a final grade. def __init__(self, weight, scored=None, out_of=None): """ Purpose: Initialize the GradeItem object. Preconditions: :param weight: the weight...

  • Major Homework #2 Implement a C program major_hw2.c to solve the 15-puzzle problem using the A*...

    Major Homework #2 Implement a C program major_hw2.c to solve the 15-puzzle problem using the A* search algorithm. 1. Objectives • To gain more experience on using pointers and linked lists in C programs. • To learn how to solve problems using state space search and A* search algorithm. 2. Background A* search and 15-puzzle problem have been introduced in the class. For more information, please read the wiki page of 15-puzzle problem at https://en.wikipedia.org/wiki/15_puzzle, and the wiki page of...

  • Major Homework #2 Implement a C program major_hw2.c to solve the 15-puzzle problem using the A* s...

    Major Homework #2 Implement a C program major_hw2.c to solve the 15-puzzle problem using the A* search algorithm. Please include pictures that the code runs and shows the different states as it reaches goal state please. 1. Objectives • To gain more experience on using pointers and linked lists in C programs. • To learn how to solve problems using state space search and A* search algorithm. 2. Background A* search and 15-puzzle problem have been introduced in the class....

  • We learn arrays (and Arrays class) in Chapter 10 and ArrayList collection in Chapter 14. This...

    We learn arrays (and Arrays class) in Chapter 10 and ArrayList collection in Chapter 14. This assignment asks you to re-do Assignment 4 by using arrays and ArrayList collections to deliver exactly the same output. The input also stays the same, which are two argument values entered at the command line when 'java' command is issued. With the use of these data structures that help to store data in certain way, you are not going to print each character immediately...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT