Question

Write a program in PYTHON that takes a string and an integer as inputs from the...

Write a program in PYTHON that takes a string and an integer as inputs from the user, and then prints a

new string that contains the letters from the original string “rotated” by the given amount.

For example, “cheer” rotated by 7 places gives the word “jolly” and “melon” rotated by -10 gives the word “cubed.”

Use built-in function: ord() to convert a character to a numeric code and chr() to convert numeric code to character.

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

def String_rotation(word, integer):
rotated_string = ''
#it will store the ASCII value of 'a' in start_limit
start_limit = ord("a")
# it will store the ASCII value of 'z' in end_limit
end_limit = ord("z")
for w in word:
char_num = ord(w) + integer
#adjustments of a character
while char_num > end_limit: char_num -= 26
while char_num < start_limit: char_num += 26
#converting an integer to character
w = chr(char_num)
rotated_string = rotated_string + w
return (rotated_string)

word =input("Enter a string for the rotation: ")
integer= int(input("Enter an integer to rotate the given string by the integer: "))
print (String_rotation(word,integer))

Output is as follows:

Add a comment
Know the answer?
Add Answer to:
Write a program in PYTHON that takes a string and an integer as inputs from the...
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
  • Using Java write a program that takes a string input from the user and then outputs...

    Using Java write a program that takes a string input from the user and then outputs the first character, then the first two, then the first three, etc until it prints the entire word.

  • Write a Python code that asks a string from the user and prints only the lower...

    Write a Python code that asks a string from the user and prints only the lower case letters in that string

  • Assembly Programming INCLUDE Irvine32.inc Make a program that takes a string and a word as inputs...

    Assembly Programming INCLUDE Irvine32.inc Make a program that takes a string and a word as inputs from the user and searches the word in the string. If it finds the word in the string, it prints “ Found”, else it prints “ Not found”. Note that i t is not searching for the matching characters but searching for the corresponding word. For example, suppose a string is “I am a teacher.” and a word for search is “tea”. Now the...

  • Write a Python function called more() that takes three string inputs and outputs a string Formally,...

    Write a Python function called more() that takes three string inputs and outputs a string Formally, the function signature and output are given by rucharist, char: str words str) > str Use the same names for the input arguments as shown above Note that charl and char2 will always be a string of length 1 (ie, it is a single character. The function checks which of charl or char2 appears more often in the word string and returns that character...

  • Python: Using chr() and ord() write a function called en_crypt() that takes into input a string...

    Python: Using chr() and ord() write a function called en_crypt() that takes into input a string and returns a new encrypted version of the input string. Example: "atwOta@0202" should return "fy|TyfE5757", then write a function de_crypt() so that "fy|TyfE5757" returns "atwOta@0202"

  • In Python 3 - Write a program that reads a sequence of integer inputs from the...

    In Python 3 - Write a program that reads a sequence of integer inputs from the user. When the user is finished entering the integers, they will enter a 'q'. There is no need to check if the entry is a valid integer. All integers in the test data (input) will be between -255 and 255. The program should then print: The smallest and largest of the inputs. The number of even and odd inputs (0 should be considered even)...

  • Write a Python function, called counting, that takes two arguments (a string and an integer), and...

    Write a Python function, called counting, that takes two arguments (a string and an integer), and returns the number of digits in the string argument that are not the same as the integer argument. Include a main function that inputs the two values (string and integer) and outputs the result, with appropriate labelling. You are not permitted to use the Python string methods (such as count(), etc.). Sample input/output: Please enter a string of digits: 34598205 Please enter a 1-digit...

  • Python program. Character-Analysis Program Problem Statement: Design a program - IN PYTHON - that asks the...

    Python program. Character-Analysis Program Problem Statement: Design a program - IN PYTHON - that asks the user to enter a string. The string will then be displayed back to the user. This is followed by determining the number of alphabetic characters, numeric characters, lower_case letters, upper_case letters, whitespace characters, and then displaying them. The user should be given additional chances to enter additional strings, and each time a string is entered, the above process is to be performed. The inputting...

  • In python. Write a program that takes 2 string inputs and calculates the Hamming Distance. Hamming...

    In python. Write a program that takes 2 string inputs and calculates the Hamming Distance. Hamming distance between two strings is the number of positions at which the corresponding symbols are different. The program should output an integer representing this distance. For example a = XXWWZZ b = ZZWWXX answer = 4 More examples: "Phone" and "PHOONE" = 3 "God" and "Dog" = 2 "Dog" and "House" = 4

  • USING C# 1. Write a program that takes outputs a string, an integer and a floating-point number s...

    USING C# 1. Write a program that takes outputs a string, an integer and a floating-point number separated by commas. Sample output: Bob Marley, 20, 5.2 2. 2. Write a program that asks the user for a string of letters of any size (no spaces), and finally a special character (values 33 to 47 in the Ascii table, or ‘!’ to ‘/’). Generate a random number of any size, integer or floating point, and combine those three pieces of information...

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