Oktatás * Programozás 2 * Szkriptnyelvek * levelezősök Félévek Linkek * kalendárium |
EnPy /
20130919ba-z; with reversed source code: z-a Write a Python script that prints the lower case letters of the English alphabet from a to z. Now reverse the source code of the script. The reversed source should also give a valid Python script, and if you run it, you should get the lower case letters of the English alphabet in a reversed way from z to a. Tip: pass your Python script to the Python interpreter, as seen below in the running example. To reverse a file, use this program ( #!/usr/bin/env python import sys def main(): with open(sys.argv[1]) as f: print f.read()[::-1] ############################################################## if __name__ == "__main__": if len(sys.argv) == 1: print "One parameter is required." sys.exit(1) # else main() Running example: $ ls -al total 20 drwxrwxr-x 2 jabba jabba 4096 Sep 19 13:31 . drwxrwxr-x 3 jabba jabba 4096 Sep 19 13:26 .. -rwx------ 1 jabba jabba 124 Sep 19 13:31 a-z.py -rwx------ 1 jabba jabba 313 Sep 19 13:22 reverse.py $ python ./a-z.py abcdefghijklmnopqrstuvwxyz $ ./reverse.py a-z.py >back.py $ ls -al total 20 drwxrwxr-x 2 jabba jabba 4096 Sep 19 13:31 . drwxrwxr-x 3 jabba jabba 4096 Sep 19 13:26 .. -rwx------ 1 jabba jabba 124 Sep 19 13:31 a-z.py -rw-rw-r-- 1 jabba jabba 125 Sep 19 13:31 back.py -rwx------ 1 jabba jabba 313 Sep 19 13:22 reverse.py $ python back.py zyxwvutsrqponmlkjihgfedcba $ The file " |
Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |