Question: I have a Python assignment, here are the requirements: Ask the user for the name of a file to open and read from. This file

I have a Python assignment, here are the requirements:

  1. Ask the user for the name of a file to open and read from. This file should be an encoded ascii art file (provided)
  2. Open the file and read the data.
  3. Because it is encoded you will need to loop through every character in the data and un-encode (decode) it
    1. You can do this with a command similar to the line below. Basically this is very similar to examples in the book and it just subtracts 1 from each characters value. Example makes 'B' into 'A'
      1. chr(ord(character) - 1)
    2. as you loop and transform each character you will need to add them to a new string. When you are done this new string should have each and every transformed character from the old string
  4. Print the new string you created. It should be a cute ascii art image
  5. Ask the user if they want to save the ascii art (Y/N)
    1. if they indicate Yes (Y) then ask them for a filename
    2. open the file for writing
    3. Save the new string you created to the file
    4. close the output file you just wrote to
  6. close the input file you read from

I'm have trouble with step 3 and 4. How can I loop the characters to a new string to print?

Here is what I have so far:

#open and read the file filename = input("Enter a filename:") artFile = open(filename, 'r') art = artFile.read()

picture = "" for letter in art: picture += chr(ord(letter) -1) print(art)

#saveArt = input("Do you want to save your artwork?") #if yes in saveArt:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!