Question

Write code in python for following Use queue to implement it Implement a decryption method String...

Write code in python for following

Use queue to implement it

Implement a decryption method String decrpt(String s) to decrypt a number sequence (stored in a string s).

The decryption algorithm works as follows:

  1. Delete the first element of the sequence
  2. Move the first element of the sequence to the end
  3. Delete the first element of the sequence
  4. Move the first element of the sequence to the end

….

This process keeps running until all element in the sequence has been deleted. Then we put all deleted element together and output the result.

E.g.

Input: “631758924”

Output: “615947283”

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

Note: Please maintain proper code spacing (indentation), just copy the code part and paste it in your compiler/IDE directly, no modifications required.

#code

#required method
def decrypt(s):
    #creating an empty string to store the deleted characters or the decrypted
    #text
   
deleted=''
   
#looping until s becomes empty
   
while len(s)>0:
        #getting first character of s
       
first=s[0]
        #removing first character from s
        #note that s[1:] returns a substring of s with first character removed
       
s=s[1:]
        #appending first to deleted
       
deleted+=first
        #checking if s is not empty
       
if len(s)>0:
            #moving first character to the last
           
s=s[1:]+s[0]
    #after the loop, returning deleted text
   
return deleted

#testing the decrypt method
print(decrypt("631758924")) #615947283

#output

615947283

Add a comment
Know the answer?
Add Answer to:
Write code in python for following Use queue to implement it Implement a decryption method String...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write python code for the following Implement a method Boolean containPattern(String s) to find the following...

    Write python code for the following Implement a method Boolean containPattern(String s) to find the following special pattern in String s: Sequence1&Sequence2 Where Sequence 1 and Sequence 2 do not contain symbol ‘&’ Sequence 2 should be the reversed version of Sequence 1 e.g. input: a+b&b+a output: true input: 1+3&3-1 output: false

  • Python use dequeue and enqueue methods, alter the dequeue method and the enqueue method. remove items...

    Python use dequeue and enqueue methods, alter the dequeue method and the enqueue method. remove items from the first element of the list (the front of the queue) and return this value and you need to add items to the last element of the list (the rear of the queue). 4. (20 points) Programming Exercise 5 from Chapter 3 of your textbook. Name the class Queuex, and use the other method names given in Chapter 3.11 in your digital textbook....

  • 3. Write Python statements that will do the following: a) Input a string from the user....

    3. Write Python statements that will do the following: a) Input a string from the user. *** Print meaningful messages along with your output.* b) Print the length of the String. Example input: The sky is blue. Correct output: The length of the string is 16 Incorrect output: 16 c) Print the first character of the string. d) Print the last character of the string. 4. Save the program. Double-check the left edge for syntax errors or warning symbols before...

  • Please use Python def findSubstrings(s):     # Write your code here Consider a string, s = "abc"....

    Please use Python def findSubstrings(s):     # Write your code here Consider a string, s = "abc". An alphabetically-ordered sequence of substrings of s would be {"a", "ab", "abc", "b", "bc", "c"}. If the sequence is reduced to only those substrings that start with a vowel and end with a consonant, the result is {"ab", "abc"}. The alphabetically first element in this reduced list is "ab", and the alphabetically last element is "abc". As a reminder: • Vowels: a, e, i,...

  • Give python code for this algorithm in two ways. 1 Method has to be recursive, Method...

    Give python code for this algorithm in two ways. 1 Method has to be recursive, Method 2 has to use list comprehensions or list traversal methods. You have to write python function that will be in this form ArithmeticSequence(0,2,10){} where 0 is the first number in the sequence, the next number goes up by 2, and stopping at the last value in sequence before 10, so 10 is the max of this sequence. it has to pass a test like...

  • Please Write Pseudocode or Python code! Thanks! P1. b) is the following: W1. (6 marks) Write...

    Please Write Pseudocode or Python code! Thanks! P1. b) is the following: W1. (6 marks) Write the pseudocode for removing and returning only the second element from the Stack. The top element of the Stack will remain the top element after this operation. You may assume that the Stack contains at least two items before this operation. (a) Write the algorithm as a provider implementing a Stack using a contiguous memory implementation. You can refer to the implementation given in...

  • Please write code in Python! You are asked to implement the following checksum formula to validate...

    Please write code in Python! You are asked to implement the following checksum formula to validate an identifi- cation number given to you. The formula works as follows. Using the original number, double the value of every other digit. Then add the values of the individual digits together (if a doubled value now has two digits, add the digits individually). The identification number is valid if the resulting sum is divisible by 10. Write a function called validateID that takes...

  • Create a Java code that includes all the methods from the Lecture slides following the ADTs...

    Create a Java code that includes all the methods from the Lecture slides following the ADTs LECTURE SLIDES Collect/finish the Java code (interface and the complete working classes) from lecture slides for the following ADTS: 4) Queue ADT that uses a linked list internally (call it LQueue) Make sure you keep the same method names as in the slides (automatic testing will be performed)! For each method you develop, add comments and estimate the big-O running time of its algorithm....

  • Hi! it is c++ queue simulation please read the instructions, write codes, and explain the code...

    Hi! it is c++ queue simulation please read the instructions, write codes, and explain the code with comments. Thank you Transactions enter the system and are stored in a queue. Each transaction represents some work that needs to be accomplished. Servers exist which process transactions. Servers take transactions off the queue and process them. you’re building the simulation framework. The idea is that somebody would take your framework, and add the specifics for whatever type of system it was going...

  • 1) Which of the following is NOT true about a Python variable? a) A Python variable...

    1) Which of the following is NOT true about a Python variable? a) A Python variable must have a value b) A Python variable can be deleted c) The lifetime of a Python variable is the whole duration of a program execution.   d) A Python variable can have the value None.        2) Given the code segment:        What is the result of executing the code segment? a) Syntax error b) Runtime error c) No error      d) Logic error 3) What...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT