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

IN PYTHON... PLEASE... do not use any advanced functions. This is a beginning pr

ID: 3919276 • Letter: I

Question

IN PYTHON...

PLEASE... do not use any advanced functions. This is a beginning programming class and please add comments if you can I really want to understand this. :)

You will write a program named flipper.py that “flips” the “pixels” of ascii-art images. Ascii-art is an image that is created by assembling rows and columns or characters to resemble an image. Below are two examples:

The first is an ascii picture of a person. This is saved in a file named person.txt

   #######    
   # 0 0 #    
   # v # %
   # O # #
   ####### #
      # #
  ########    
  # #   #
# #   #
#   # #     
%    #####     
    ## ##     
   ## ##     
  ## ##
000   000

The second ascii image file is vader.txt, and it shows Darth Vader:

                      .-.
                     |_:_|
                    /(_Y_)
.                   ( /M/ )
'.               _.'-/'-'-'._    
  ':          _/.--'[[[[]'--._       
    ':     /_' : |::"| : '.
      ': //   ./ |oUU| .' :
        ': _:'..' _|___|_/ :   :|
          ':. .' |_[___]_| :.':
           [:: | : | | : ; :
            '-' /'.| |.' .;.' |
            |_ '-'   : |
            | .:   : | |
            | | '.   : |
            / :. .;       |
           / | | :__/     : \
          | | | :   | | ||
         / : : |: / |__| /|
         | : : :_/_| /'._ '--|_
         /___.-/_|-'      

Notice that each of these images has the same exact number of characters on each row. This is important because rows in an image must all be of the same length for it to appear “square”. For the case of these files, this means padding the ends of the lines with space characters. Your program should work on any ascii image file, with any width and height), so do not just test with these two. These are just two as a running example for this assignment spec.

You will write a program that flips the characters in these images in various ways. Your program will take three inputs. The first should be the name of the file containing the image to flip. The second will be the name of the new file to save the flipped image. The third will be either “lr” (left-right) or “ud” (up-down). You would use the input() function to get these values.

Select an image file: person.txt
Select an output file: person_lr.txt
Select a direction (lr, ud): lr

Your program must ensure that the third input is either lr or ud. If it does not match either input, then print a warning message and then ask for the input again. It SHould do this until a correct input is provided.

Flipping person.txt and vader.txt in lr mode should result in the outfiles having these contents respectively:

    #######    
    # 0 0 #    
%   # v #    
# # O #
  # #######    
   # #       
    ########   
     # # #   
     # # #
     # # #
     #####   %
     ## ##    
     ## ##    
     ## ##   
    000 000

              .-.           
             |_:_|             
            )_Y_(/               
           ) /M/ (                .
         _.'-'-'/-'._               .'
       _.--'][[[['--./_           :'
      .' : |"::| : '_/ :'
     : '. |UUo| /.   // :'
    |: : /_|___|_ '..':_ :'
    :'.: |_]___[_| '. .:'       
    : ;   : | | : | ::[       
  | '.;. '.| |.'/   '-'
  |     : '-'    _|
  | |   : :.     |    
  |    : .' |     |      
  |     ;. .:       /
\ : /__: |   | /         
||   | |   : | | |
|/   |__| /   :| : :    /
_|--' _.'/ |_/_: : :     |
             '-|_/-.___/          

Flipping both files in ud mode should result in the following contents:

000   000
  ## ##   
   ## ##      
    ## ##      
%    #####      
#   # #      
# #   #
  # #   #
  ########     
      # #
   ####### #   
   # O # #
   # v # %
   # 0 0 #     
   #######     

         /___.-/_|-'      
         | : : :_/_| /'._ '--|_
         / : : |: / |__| /|
          | | | :   | | ||
           / | | :__/     : \
            / :. .;       |
            | | '.   : |
            | .:   : | |
            |_ '-'   : |
            '-' /'.| |.' .;.' |
           [:: | : | | : ; :
          ':. .' |_[___]_| :.':
        ': _:'..' _|___|_/ :   :|
      ': //   ./ |oUU| .' :
    ':     /_' : |::"| : '.
  ':          _/.--'[[[[]'--._        
'.               _.'-/'-'-'._     
.                   ( /M/ )
                    /(_Y_)
                     |_:_|
                      .-.

Note that flipping an image in the same direction twice in a row should result in the same exact image as the original. Use this technique to ensure that your are flipping correctly



When writing your program, you may only use the following built-in list and string methods:

len()

list()

append()

No other built-in methods can be used! You can not use reverse(), or any others! You must use 2D lists to represent the rows and columns of the text images!

Several example inputs/output files will be provided to test your program with the diff-tester.

   #######    
   # 0 0 #    
   # v # %
   # O # #
   ####### #
      # #
  ########    
  # #   #
# #   #
#   # #     
%    #####     
    ## ##     
   ## ##     
  ## ##
000   000

Explanation / Answer

here is your program : --------------->>>>>>>>>>>>>

import sys

def flipUPDOWN(l):
    l1 = []
    i = len(l)-1
    while i >= 0:
        l1.append(l[i])
        i = i -1
    return l1

def flipLR(l):
    lr = []
    for i in range(len(l)):
        l2 = l[i]
        print(l2)
        l3 = []
        j = len(l2)-1
        while j >= 0:
            l3.append(l2[j])
            j = j - 1
        print(l3)
        lr.append(l3)
    return lr


def main():
    f1 = input("Select an image file: ")
    f2 = input("Select an output file: ")
    cmd = ""
    while cmd == "":
        cmd = input("Select a direction (lr,ud): ")
        if cmd == "lr" or cmd == "ud":
            break
        else:
            cmd = ""
    try:
        mf1 = open(f1,"r")
        mf2 = open(f2,"w")
    except IOError:
        print("Could not open file! Please check input file ")
        sys.exit()
    l = []
    for line in mf1:
        line = line[:-1]
        l.append(list(line))
    l1 = []
    print(l)
    if cmd == "lr":
        l1 = flipLR(l)
    elif cmd == "ud":
        l1 = flipUPDOWN(l)
    if l1 != []:
        for i in range(len(l1)):
            st = ''.join(l1[i])
            st = st + " "
            mf2.write(st)

main()