Question

Write a Python program to ask user input of a string, then ask user input of...

  1. Write a Python program to ask user input of a string, then ask user input of what letters they want to remove from the string. User can either put in "odd", "even" or a number "n" that is greater than 2. When user input "odd", it will remove the characters which have odd numbers in the sequence of the string. When user input "even", it will remove the characters which have even numbers in the sequence of the string. When user input "n" number, it will remove the characters which have nth numbers in the sequence of the string. Note that we are talking about the sequence of the letters, so the first letter in a string is number 1, the second is number 2, and so on.

Example:

Input string = "abcdef"

Input choice = "odd"

Output = "bdf"

Input string = "python"

Input choice = "even"

Output = "pto"

Input string = "abcdef"

Input choice = "3"

Output = "abde"

Homework Answers

Answer #1

s=input("Enter input string:")
ch=input("Enter choice:")#read inputs from user
res=""
if ch=="odd":#if choice is odd
for i in range(1,len(s)+1):
if i%2==0:#add only even placed characters
res+=s[i-1]
  
elif ch=="even":#if choice is even
for i in range(1,len(s)+1):
if i%2!=0:#add only odd placed characters
res+=s[i-1]
else:
ch=int(ch)
for i in range(1,len(s)+1):
if i%ch!=0:#if i is not multiple of ch entered
res+=s[i-1]#append the characters
print("Output = ",res)
  

Screenshots:

The screenshots are attached below for reference.

Please follow them for output and proper indentation.

Please upvote my answer. Thank you.

.

Know the answer?
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
Similar Questions
By using Python code answer the following parts: A) Write a program to ask the user...
By using Python code answer the following parts: A) Write a program to ask the user to input their name and then output the type and length of the input. B) Write a program to output the last 11 letters of 'Introduction to Indiana'. C) Write a program to output the 3rd to the 11th letters of 'Introduction to Indiana'. D) Write a program to ask the user to input a float number and output the rounded value of it...
1) In Python Use a while loop to ask the user to enter a series of...
1) In Python Use a while loop to ask the user to enter a series of alphabets. The loop terminates when the user presses enter. Once the loop terminates, display the number of vowels and consonants entered by the user. Hint: keep a running count of the number of characters entered by the user. Keep a running count of the number of vowels. Total number of consonants = total number of characters - total number of vowels. Assume that the...
Write a Java program that prompts the user to input a word (String). The program must...
Write a Java program that prompts the user to input a word (String). The program must print the reversed word with all consecutive duplicate characters removed. The program must contain the following classes: - The StackX class (you can use the Java Stack class). - The Reverse class which must contain a private data field called “word” of type string, a constructor, and a void method called revNoDup(). The revNoDup() method must reverse the word and remove the consecutive duplicate...
user will input a set of integers until 0 is input. When each number is input,...
user will input a set of integers until 0 is input. When each number is input, output whether the number input is it even or odd. Additionally, count the even numbers input. When 0 is input, output the count of the even numbers. Write the code here including the class definition and main function:
C++ Write a program that will ask the user to input n positive numbers. The program...
C++ Write a program that will ask the user to input n positive numbers. The program will terminate if one of those number is not positive. please respond quickly and clearly, thank you!
Write a Java application a String input by the user and shows whether the string contains...
Write a Java application a String input by the user and shows whether the string contains all 26 letters of the (English version of the Latin) alphabet. For example, "Pack my box with five dozen liquor jugs" contains all 26 letters, but "The quick frown box jumps over the hazy log" does not contain a d. It does not matter whether one or more letters appear more than once. needs, at minimum, asl user to input for the String, then...
Write a program that prompts the user to input a string and outputs the string in...
Write a program that prompts the user to input a string and outputs the string in uppercase letters. (Use dynamic arrays to store the string.) my code below: /* Your code from Chapter 8, exercise 5 is below. Rewrite the following code to using dynamic arrays. */ #include <iostream> #include <cstring> #include <cctype> using namespace std; int main() { //char str[81]; //creating memory for str array of size 80 using dynamic memory allocation char *str = new char[80]; int len;...
Write a program that accepts an input string from the user and converts it into an...
Write a program that accepts an input string from the user and converts it into an array of words using an array of pointers. Each pointer in the array should point to the location of the first letter of each word. Implement this conversion in a function str_to_word which returns an integer reflecting the number of words in the original string. To help isolate each word in the sentence, convert the spaces to NULL characters. You can assume the input...
Use Python: # Problem Set 03: - Write a program to input an uncertain string *S*...
Use Python: # Problem Set 03: - Write a program to input an uncertain string *S* of words and space/tab - Remove space/tab in S - Remove identical words - Sort all words in the order of a-z - Print the output strings - Example: - Input String: "hello world and practice makes perfect and hello world again" - Output String: "again and hello makes perfect practice world" - Tips: - use *set* to remove identical words, - use *sorted()*...
On Python Ask the user to input a min and a max value for a range...
On Python Ask the user to input a min and a max value for a range of numbers. Then use range(min, max) to: a) Loop through the range specified by the user and find all the numbers that are divisible by 3 and print them. b) Loop through the range and find only the first multiple of 3 and print it.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT