Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi am having a problem doing this questions , Write a program doGraphics.py that

ID: 3536059 • Letter: H

Question

Hi am having a problem doing this questions ,

Write a program doGraphics.py that creates a drawing from a series of instructions stored in the program as string such as

Write a new program doGraphics_ReadFromFile.py (based on your earlier doGraphics program) that reads its instructions from a textfile named instructions.txt. Like before, this program interprets the instructions and draws the graphic.

Write a further program doGraphics_ReadFromFileAndWrite.py that again reads the drawing instructions from the textfile. Yet, instead of presenting the drawing on the screen, this program modifies the drawing instructions and writes the modified instructions into a new file.

The filename for the new file has to be the old name with ‘_modified’ added. So, ‘instructions.txt’ becomes ‘instructions_modified.txt’. It is important that your solution works for any filename with extension ‘.txt’, that means you have to use string operations to modify the existing filename.

The modifications to the drawing instructions are that you replace any instruction to draw a rectangle with four separate instructions for drawing lines.


      1  2  3  4  5  6  7  
      drawingInstructions = """r 200 200 100 80  l 235 200 220 180  l 235 200 240 175  l 245 200 270 180  r 220 220 20 20  r 260 220 20 20  r 240 260 30 10"""  

Explanation / Answer

#/usr/bin/python import sys drawingInstructions = """r 200 200 100 80 l 235 200 220 180 l 235 200 240 175 l 245 200 270 180 r 220 220 20 20 r 260 220 20 20 r 240 260 30 10""" foo = [ (32, 4), (95, 8), (32, 3), (95, 2), (32, 4), (95, 2), (32, 4), (95, 7), (32, 3), (95, 2), (32, 4), (95, 2), ('RL', 1), (32, 3), (124, 1), (9, 1), (32, 4), (124, 1), (32, 1), (124, 1), (32, 2), (124, 1), (32, 2), (124, 1), (32, 2), (124, 1), (32, 2), (47, 1), (9, 1), (32, 2), (124, 1), (32, 1), (124, 1), (32, 2), (124, 1), (32, 2), (47, 1), (32, 2), (47, 1), ('RL', 1), (32, 3), (124, 1), (32, 2), (45, 6), (39, 1), (32, 1), (124, 1), (32, 2), (124, 1), (32, 2), (124, 1), (32, 2), (124, 1), (32, 2), (124, 1), (32, 3), (95, 4), (124, 1), (32, 1), (124, 1), (32, 2), (124, 1), (32, 1), (47, 1), (32, 2), (47, 1), ('RL', 1), (32, 3), (124, 1), (32, 2), (124, 1), (95, 3), (32, 4), (124, 1), (32, 2), (124, 1), (32, 2), (124, 1), (32, 2), (124, 1), (32, 2), (124, 1), (32, 2), (124, 1), (9, 1), (32, 4), (124, 1), (32, 2), (124, 1), (47, 1), (32, 2), (47, 1), ('RL', 1), (32, 3), (124, 1), (32, 3), (95, 3), (124, 1), (32, 3), (124, 1), (32, 2), (124, 1), (32, 2), (124, 1), (32, 2), (124, 1), (32, 2), (124, 1), (32, 2), (124, 1), (9, 1), (32, 4), (124, 1), (9, 1), (32, 2), (47, 1), ('RL', 1), (32, 3), (124, 1), (32, 2), (124, 1), (32, 7), (124, 1), (32, 2), (124, 1), (32, 2), (124, 1), (32, 2), (124, 1), (32, 2), (124, 1), (32, 2), (124, 1), (95, 4), (32, 2), (124, 1), (9, 1), (32, 2), (92, 1), ('RL', 1), (32, 3), (124, 1), (32, 2), (124, 1), (32, 7), (124, 1), (32, 3), (45, 2), (32, 3), (124, 1), (32, 2), (124, 1), (9, 1), (32, 2), (124, 1), (32, 1), (124, 1), (32, 2), (124, 1), (92, 1), (32, 2), (92, 1), ('RL', 1), (32, 3), (124, 1), (95, 2), (124, 1), (32, 7), (92, 1), (95, 8), (47, 1), (32, 3), (92, 1), (95, 6), (124, 1), (32, 1), (124, 1), (95, 2), (124, 1), (32, 1), (92, 1), (95, 2), (92, 1), ('RL', 1), ('RL', 1), (9, 4), (32, 5), (95, 5), ('RL', 1), (9, 4), (32, 4), (124, 2), (9, 1), (32, 1), (124, 2), ('RL', 1), (9, 4), (32, 4), (124, 1), (92, 1), (95, 3), (47, 1), (124, 1), ('RL', 1), (9, 4), (32, 4), (124, 1), (9, 1), (32, 2), (124, 1), ('RL', 1), (9, 4), (32, 4), (124, 1), (9, 1), (32, 2), (124, 1), ('RL', 1), (9, 4), (32, 4), (124, 1), (9, 1), (32, 2), (124, 1), ('RL', 1), (9, 4), (32, 4), (124, 1), (9, 1), (32, 2), (124, 1), ('RL', 1), (9, 4), (32, 4), (124, 1), (9, 1), (32, 2), (124, 1), ('RL', 1), (9, 4), (32, 4), (124, 1), (9, 1), (32, 2), (124, 1), ('RL', 1), (9, 3), (32, 7), (95, 5), (124, 1), (60, 1), (45, 3), (62, 1), (124, 1), (95, 5), ('RL', 1), (9, 3), (32, 6), (47, 1), (32, 5), (124, 1), (9, 1), (32, 2), (124, 1), (9, 1), (92, 1), ('RL', 1), (9, 3), (32, 1), (47, 1), (32, 4), (124, 1), (32, 5), (124, 1), (9, 1), (32, 2), (124, 1), (9, 1), (124, 1), (32, 1), (92, 1), ('RL', 1), (9, 3), (32, 1), (124, 1), (32, 4), (124, 1), (32, 5), (124, 1), (9, 1), (32, 2), (124, 1), (9, 1), (124, 1), (32, 2), (124, 1), ('RL', 1), (9, 3), (32, 1), (124, 1), (32, 4), (124, 1), (32, 5), (124, 1), (9, 1), (32, 2), (124, 1), (9, 1), (124, 1), (32, 2), (124, 1), ('RL', 1), (9, 3), (32, 1), (124, 1), (9, 3), (124, 1), (32, 2), (124, 1), ('RL', 1), (9, 3), (32, 1), (124, 1), (9, 3), (124, 1), (32, 2), (124, 1), ('RL', 1), (9, 3), (32, 1), (124, 1), (9, 3), (32, 2), (47, 1), ('RL', 1), (9, 3), (32, 1), (124, 1), (9, 3), (32, 1), (47, 1), ('RL', 1), (9, 3), (32, 2), (92, 1), (9, 2), (32, 7), (47, 1), ('RL', 1), (9, 3), (32, 3), (92, 1), (9, 2), (32, 6), (47, 1), ('RL', 1), (9, 3), (32, 4), (124, 1), (9, 2), (32, 6), (124, 1), ('RL', 1), (9, 3), (32, 4), (124, 1), (9, 2), (32, 6), (124, 1), ('RL', 1), ('RL', 1), (9, 4), (32, 5), (95, 4), (32, 5), (95, 4), (32, 2), (95, 9), (9, 1), (95, 3), (9, 1), (95, 3), ('RL', 1), (9, 4), (32, 5), (92, 1), (9, 1), (32, 1), (92, 1), (32, 3), (47, 1), (9, 1), (32, 1), (47, 1), (32, 1), (47, 1), (9, 1), (32, 5), (92, 1), (32, 1), (124, 1), (32, 3), (124, 1), (32, 3), (124, 1), (32, 3), (124, 1), ('RL', 1), (9, 4), (32, 6), (92, 1), (32, 3), (92, 1), (32, 1), (47, 1), (9, 1), (47, 1), (32, 2), (124, 1), (32, 2), (95, 5), (32, 2), (124, 1), (32, 1), (124, 1), (32, 3), (124, 1), (32, 3), (124, 1), (32, 3), (124, 1), ('RL', 1), (9, 4), (32, 7), (92, 1), (32, 7), (47, 1), (32, 3), (124, 1), (32, 1), (124, 1), (9, 1), (32, 3), (124, 1), (32, 1), (124, 1), (32, 1), (124, 1), (32, 3), (124, 1), (32, 3), (124, 1), (32, 3), (124, 1), ('RL', 1), (9, 5), (92, 1), (32, 5), (47, 1), (32, 4), (124, 1), (32, 1), (124, 1), (9, 1), (32, 3), (124, 1), (32, 1), (124, 1), (32, 1), (124, 1), (32, 3), (124, 1), (32, 3), (124, 1), (32, 3), (124, 1), ('RL', 1), (9, 5), (32, 1), (124, 1), (32, 3), (124, 1), (9, 1), (32, 3), (124, 1), (32, 1), (124, 1), (9, 1), (32, 3), (124, 1), (32, 1), (124, 1), (32, 1), (124, 1), (32, 3), (124, 1), (32, 3), (124, 1), (32, 3), (124, 1), ('RL', 1), (9, 5), (32, 1), (124, 1), (32, 3), (124, 1), (9, 1), (32, 3), (124, 1), (32, 1), (124, 1), (95, 5), (124, 1), (32, 1), (124, 1), (32, 1), (124, 1), (32, 3), (124, 1), (95, 3), (124, 1), (32, 3), (124, 1), ('RL', 1), (9, 5), (32, 1), (124, 1), (32, 3), (124, 1), (9, 1), (32, 3), (124, 1), (9, 1), (32, 5), (124, 1), (32, 1), (124, 1), (9, 1), (32, 3), (124, 1), ('RL', 1), (9, 5), (32, 1), (124, 1), (95, 3), (124, 1), (9, 1), (32, 3), (92, 1), (95, 9), (47, 1), (32, 1), (92, 1), (95, 11), (47, 1), ('RL', 1), ] for i in foo: (ch,cnt) = i if ch == "RL": sys.stdout.write(" ") else: sys.stdout.write(chr(ch)*cnt)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote