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

    Join Date
    Mar 2013
    Rep Power

    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 Specialist (4000 - 4499 posts)

    Join Date
    Oct 2003
    Rep Power
    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 God 1st Plane (5500 - 5999 posts)

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

    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo