Question

In: Computer Science

Creating a list/tuple 4. Write a program to accept a string from the user, then replace...

Creating a list/tuple

4. Write a program to accept a string from the user, then replace the first letter with the last letter, the last letter with the middle letter and the middle letter with the first letter. E.g. “Billy” -> “yiBll”.

Solutions

Expert Solution

Code according to problem:

st = input('Enter String: ')
string = list(st)
string[0], string[len(string)-1] = string[len(string)-1],string[0]
string[len(string)-1], string[int(len(string)/2)] = string[int(len(string)/2)],string[len(string)-1]
string[0], string[int(len(string)/2)] = string[int(len(string)/2)],string[0]
new=""
for x in string:
new += x
print(new)

Code according to example:

st = input('Enter String: ')
string = list(st)
string[0], string[len(string)-1] = string[len(string)-1],string[0]
string[len(string)-1], string[int(len(string)/2)] = string[int(len(string)/2)],string[len(string)-1]
new=""
for x in string:
new += x
print(new)

Actually the statement of code and the example does not match. But I gave you code for both according to the problem statement and the example.


Related Solutions

Write a program that accept an integer input from the user and display the least number...
Write a program that accept an integer input from the user and display the least number of combinations of 500s, 100s, 50s, 20s, 10s, 5s, and 1s. Test your solution using this samples] a. Input: 250 Output: 1x200s, 1x50s b. Input: 1127 Output: 5x200s, 1x100s, 1x20s, 1x5s, 2x1s c. Input: 1127 Output: 5x200s, 1x100s, 1x20s, 1x5s, 2x1s d. Input: 19 Output: 1x10s, 1x5s, 4x1s ​[Hints] o Use division to determine the number of occurrence of each element (i.e. 200, 100)...
Task 4:         Tuples Explain what is the difference between list, string and tuple? Create a list...
Task 4:         Tuples Explain what is the difference between list, string and tuple? Create a list example and check whether you could change the item within the list. Create a string example and check whether you could change the item within the string. Create a tuple example and check whether you could change the item within the tuple.
Write a program to perform the following two tasks: 1. The program will accept a string...
Write a program to perform the following two tasks: 1. The program will accept a string as input in which all of the words are run together, but the first character of each word is uppercase. Convert the string to a string in which the words are separated by spaces and only the first word starts with an uppercase letter. For example, the string "StopAndSmellTheRose" would be converted to "Stop and smell the rose". Display the result string. 2. Then...
Write a program to perform the following two tasks: 1. The program will accept a string...
Write a program to perform the following two tasks: 1. The program will accept a string as input in which all of the words are run together, but the first character of each word is uppercase. Convert the string to a string in which the words are separated by spaces and only the first word starts with an uppercase letter. For example, the string "StopAndSmellTheRose" would be converted to "Stop and smell the rose". Display the result string. 2. Then...
Using MatLab Write a program which will: a. Accept two numbers from the user m and...
Using MatLab Write a program which will: a. Accept two numbers from the user m and n b. Define an array with the dimensions a(n,m) and fill it with random numbers in the range of -100 to 100 inclusive. c. Accept from the user two row numbers. Multiply the two rows (element by element) and find the sum. Print the result. d. Accept from the user two column numbers. Add the two columns (element by element) and find the sum....
Question 1: Write a program to receive a string from the user and compares the first...
Question 1: Write a program to receive a string from the user and compares the first and second half of the word and prints “First and Second Half Same” or “First and Second Half Different”. If the length of the word is odd, ignore the middle letter. For example: Run 1: Enter a word: abcdabc First and Second Half Same Run 2: Enter a word: abcde First and Second Half Different Hint: use the Math.floor() and length() to get the...
2. Write a Java program to read a string (a password)from the user and then   check...
2. Write a Java program to read a string (a password)from the user and then   check that the password conforms to the corporate password policy.   The policy is:   1) the password must be at least 8 characters   2) the password must contain at least two upper case letters   3) the password must contain at least one digit   4) the password cannot begin with a digit   Use a for loop to step through the string.   Output “Password OK” if the password...
Write a program to remove extra blanks from text files. Your program should replace any string...
Write a program to remove extra blanks from text files. Your program should replace any string of two or more blanks with one single blank. It should work as follows: * Create a temporary file. * Copy from the input file to the temporary file, but do not copy extra blanks. * Copy the contents of the temporary file back into the original file. * Remove the temporary file. Your temporary file must have a different name than any existing...
Write a Python program which prompts the user to input a string. Then, print the string...
Write a Python program which prompts the user to input a string. Then, print the string in reverse to the terminal Sample output Please enter a word: "zeus" The reverse of zeus is suez Hint: There are several ways to accomplish this. Recall that a string is an itterable object and therefore can be used with a for loop
Write a MIPS assembly program that prompts the user first for a string, then for a...
Write a MIPS assembly program that prompts the user first for a string, then for a character. The program should then search the string for the character and print out the number of times the character appears in the string. You can use as many restrictions as you want, just be sure to list them. You must allocate space in the .data segment of your program for the user string.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT