#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    Python encription (college intro assignment)


    Any help or tips will be appreciated! Thanks!

    Please answer in version 3.3!

    You will write a Python module which will do a simple scrambling of a string. The module asks two questions to the user:
    - the string to be scambled (call it A in the module)
    - a scrambling key, N (that should be smaller than half the length of the string)

    The module will read the string, then:

    Check if N is larger than half the length of the string. If N is larger, enter a while loop that asks the user to enter in a new value for N with the following phrase written to the terminal "Scrambling key too long, enter a smaller value:". Keep iterating this loop while N remains greater than half the length of the string. (In other words: If N is larger you may want to use a statement such as: "while" N is longer than half the string length ask the user to enter a new value for N, and keep repeating until the condition is no longer satistfied. And don't forget about SYNTAX for loops and conditional statements.)
    reverse its N first characters
    reverse its N last characters

    in that order, and print the resulting string.

    Examples of output after steps 2 and 3:

    The string "This is a test" with the key 4 will be scrambled to "sihT is a tset"
    The string "Another example" with the key 2 will be scrambled to "nAother exampel"
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,733
    Rep Power
    1959
    You already have some hint in the assignment: "while" and SYNTAX for loops and conditional statements

    The first think you could/should do is to look up how Control Flow works.

    You should also take a look at the sticky posts at top of of the forum.
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,996
    Rep Power
    481
    Here's a big chunk of the solution but I had to scramble it.

    Code:
    ver(tsil(nioj.''ersed(A[:n]))+list(A[n:-n])+list(re)))]:n-[A(desrev
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo