Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Easy script problem
#3
(Jul-22-2017, 01:10 PM)ichabod801 Wrote: It's mainly an indentation problem. You have an outer loop that loops through the distances. You have an inner loop that loops through the characters in the plain text (you call that word, which is confusing, because it's just a character).

Your output is getting longer and longer because you never reset it. You want to reset code each time you loop to a new distance. You check to see if the character is over 127, but you only do that at the end of the loop over the phrase, so it's only checking the last character in the phrase. Likewise, you only add to the output (code) at the end of the loop over the phrase. So you are only outputting the last character for each distance.

Also, your correction for the "word" being over 127 is wrong. All you need to do is subtract 95.
Should I use a while loop? I tried to change it a little
phrase = input("Write here the frase to encrypt -> ")
code = ""
n = 0
while True:
    for character in phrase:
        crypt = ord(character)
        n += 1
        if n >= 127:
            break
        if ord(character) > 127:
            crypt_1 = crypt - 95
    crypt_1 = crypt + n
    code = chr(crypt_1)
print("Your encrypted code could be one of the following: ", code, "\n")
Reply


Messages In This Thread
Easy script problem - by Niko047 - Jul-22-2017, 12:38 PM
RE: Easy script problem - by ichabod801 - Jul-22-2017, 01:10 PM
RE: Easy script problem - by Niko047 - Jul-22-2017, 02:58 PM
RE: Easy script problem - by ichabod801 - Jul-22-2017, 03:13 PM
RE: Easy script problem - by Niko047 - Jul-22-2017, 03:33 PM
RE: Easy script problem - by ichabod801 - Jul-22-2017, 09:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with a simple script Niko047 2 3,429 Jul-21-2017, 09:02 PM
Last Post: Niko047

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020