0

Need help solve

Write a program and algorithm that accepts a codeword and displays the substitution lists for the codeword. For example, given the codeword “sauerkraut”, the program should display abcdefghijklmnopqrstuvwxyz stuvwxyzabcdefghijklmnopqr abcdefghijklmnopqrstuvwxyz uvwxyzabcdefghijklmnopqrst efghijklmnopqrstuvwxyzabcd klmnopqrstuvwxyzabcdefghij rstuvwxyzabcdefghijklmnopq abcdefghijklmnopqrstuvwxyz tuvwxyzabcdefghijklmnopqrs

20th Feb 2021, 1:24 AM
Redo
8 odpowiedzi
0
Using set to remove duplicates is fine, but I didn't understand why you would want to remove the duplicates.
20th Feb 2021, 6:15 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 6
Your attempts??
20th Feb 2021, 2:24 AM
Abhiyantā
Abhiyantā - avatar
+ 2
Redo Not sure I fully understood what you are trying to do, but have a look at the following adaptation to see if it helps. My question for you - Why use a set, when all it does in this situation is remove duplicates of letters, which then renders your cypher unreadable. message=input() or "test" print("Input text: ",message,'\n') letter=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"] size=len(letter) message=' '.join(sorted(set(message), key=message.index)) print(message,'\n') # Why use a set? #print(letter) for first in message: for x in range(len(letter)): if first==letter[x]: print(''.join(letter[x:size]+letter[0:x-size]))
20th Feb 2021, 5:23 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Rishav Tiwari print("Input text: ") message=input(str()) letter=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"] size=len(letter) message=' '.join(sorted(set(message), key=message.index)) print(letter) for first in message: for x in range(len(letter)): if first==letter[x]: print(letter[x:size]+letter[0:x-size])
20th Feb 2021, 3:58 AM
Redo
+ 1
Rik Wittkopp my code attempt don't know if that's correct so hmm if using a set is wrong so what keyword should i use to remove this duplicate letters? Plus I'm a beginner
20th Feb 2021, 6:13 AM
Redo
0
Rik Wittkopp yeah don't understand to can you correct me that way hmm , i try running my code but it's not like with the problem rather the given estated sauerkraut abcdefghijklmnopqrstuvwxyz stuvwxyzabcdefghijklmnopqr abcdefghijklmnopqrstuvwxyz uvwxyzabcdefghijklmnopqrst efghijklmnopqrstuvwxyzabcd klmnopqrstuvwxyzabcdefghij rstuvwxyzabcdefghijklmnopq abcdefghijklmnopqrstuvwxyz tuvwxyzabcdefghijklmnopqrs message = input("Enter a codeword :") string = "abcdefghijklmnopqrstuvwxyz" size=len(string) message=' '.join(sorted(set(message), key= message.index)) print(string) for first in message: for i in range(len(string)): if first==string[i]: print(string[i:size]+string[0:i-size]) output for my code attempt : abcdefghijklmnopqrstuvwxyz stuvwxyzabcdefghijklmnopqr abcdefghijklmnopqrstuvwxyz uvwxyzabcdefghijklmnopqrst efghijklmnopqrstuvwxyzabcd rstuvwxyzabcdefghijklmnopq klmnopqrstuvwxyzabcdefghij tuvwxyzabcdefghijklmnopqrs
20th Feb 2021, 11:04 AM
Redo
0
Solve it coligula
21st Feb 2021, 11:06 AM
Loonch
Loonch - avatar