Question

In: Computer Science

**To Be Written in Python for Beginners** Overview Do you know what an alternade is? Of...

**To Be Written in Python for Beginners**

Overview Do you know what an alternade is? Of course you don’t, no one does! According to Wikipedia, an alternade: “is a word in which its letters, taken alternatively in a strict sequence, and used in the same order as the original word, make up at least two other words. All letters must be used, but the smaller words are not necessarily of the same length. For example, a word with seven letters where every second letter is used will produce a four-letter word and a three-letter word.” In most cases, the alternade is formed by looking at letters that are two spaces apart, with the first word starting at position 0, and the second from position 1. For example, the word “pained” is an alternade, because using the rules above we produce 2 words: “pie” and “and” Your job is to write a Python program that asks the user to make one of two choices…destruct or construct. If the user chooses destruct, prompt them for an alternade, and then output the 2 words from that alternade. If the user chooses construct, prompt them for 2 words, and then output the alternade that would have produced those words. You must enforce that the users enter real words…or at least not blatant non-words. So if their input contains numbers, whitespace, punctuation, etc., you should prompt them for input until correct input is provided. **You can assume the word entered is of even length, but if you want a challenge, figure out how to implement if the length of the word is even or odd.** If you manage to get all that done, then implement the following: the words output by your program must be in alternating case, starting with uppercase. So, for example, if you wanted to output the word “happy”, it should be displayed as “HaPpY.”

Solutions

Expert Solution

def alternate_word(word):#a  function is defined 
    W2 = ''
    for i in range(len(word)):
        if i % 2 == 0:
            W2 += word[i].upper()#if the word is at even positon then it will be converted to uppercase else it will be converted to lowecase
        else:
            W2 += word[i].lower()
    return W2


choice = input(
    'Select your option : \n 1. Enter d for destruct \n 2. Enter c for construct: \n')#enter your choice 

if choice.lower() == 'd':
    word = input('Enter the alternade: ')
    while not word.isalpha():
        word = input('Word is not a valid so,try  again: ')
    W1 = word[::2]
    W2 = word[1::2]
    print('First word: ', W1)
    print('Second word: ', W2)
else:
    W1 = input('Enter first word: ')#it will take input of first word from the user 
    while not W1.isalpha():
        W1 = input('Word is not a valid so,try  again: ')
    W2 = input('Enter second word: ')#it will take input of second word from the user 
    while not W2.isalpha():
        W2 = input('Word is not a valid so,try  again: ')
    word = ''
    for i in range(len(W2)):
        word += W1[i]+W2[i]
    word += W1[len(W2):]
    #alternate_word function is called 
    print('Alternade is:', alternate_word(word))#it will give the final output 

Here is your output screen:

if you have any problem regarding this question then feel free to ask in comment section.if you like the code then give a thumbsup.


Related Solutions

What do you know about programming in Python? What is the difference between Python and Java?
What do you know about programming in Python? What is the difference between Python and Java? What does the term Open Source mean? Name four examples of Open Source software. What is the IDEL programming environment? How does IDEL relate to Python? How do you spread a long statement over multiple lines in Python? How do you use the loop-index? How will knowing and understanding Python impact what you do in your profession and/or personal experiences?
Writing python code: Can you do for me this. The question looks bellow Overview : As...
Writing python code: Can you do for me this. The question looks bellow Overview : As a programmer, you have be asked by a good friend to create a program that will allow them to keep track of their personal expenses. They want to be able to enter their expenses for the month, store them in a file, and then have the ability to retrieve them later. However, your friend only wants certain people to have the ability to view...
Using Python code create a program only with beginners code. You are taking online reservations at...
Using Python code create a program only with beginners code. You are taking online reservations at the The inn Ask for your client’s name and save in a variable Ask how many nights your client will be staying and save in a variable Room rental is $145 per night Sales tax is 8.5% Habitation tax is $5 per night (not subject to sales tax) Print out: Client’s name Room rate per night Number of nights Room cost (room rate *...
hi i do not know what is wrong with my python code. this is the class:...
hi i do not know what is wrong with my python code. this is the class: class Cuboid: def __init__(self, width, length, height, colour): self.__width = width self.__length = length self.__height = height self.__colour = colour self.surface_area = (2 * (width * length) + 2 * (width * height) + 2 * (length * height)) self.volume = height * length * width def get_width(self): return self.__width def get_length(self): return self.__length def get_height(self): return self.__height def get_colour(self): return self.__colour def set_width(self,...
In Python please! Given an unsorted list (ls) of values (you do not know the datatype)....
In Python please! Given an unsorted list (ls) of values (you do not know the datatype). Only two values appear in the list but they appear many times and are not sorted. Without using any significant additional space (i.e. you cannot copy the list) sort the elements in linear time going through the list only once. For example: Given the list [‘a’, ‘a’, ‘b’, ‘a’, ‘a’, ‘b’, ‘b’, ‘a’] after the function, the list is [‘a’, ‘a’, ‘a’, ‘a’, ‘a’,...
Overview The written assignments will present you with a scenario that has legal implications and ask...
Overview The written assignments will present you with a scenario that has legal implications and ask you to identify the legal issues involved and make recommendations as to how to best handle the situation. The written assignments may be turned in at any time between the time the unit begins and the deadline for that unit. Read the scenario below and answer the questions that follow. Submit your answers in the form of a Word or PDF file. Instructions George...
Python code Assignment Overview In this assignment you will practice with conditionals and loops (for). This...
Python code Assignment Overview In this assignment you will practice with conditionals and loops (for). This assignment will give you experience on the use of the while loop and the for loop. You will use both selection (if) and repetition (while, for) in this assignment. Write a program that calculates the balance of a savings account at the end of a period of time. It should ask the user for the annual interest rate, the starting balance, and the number...
Overview: You will write a python program that will work with lists and their methods allowing...
Overview: You will write a python program that will work with lists and their methods allowing you to manipulate the data in the list. Additionally you will get to work with randomization. Instructions: Please carefully read the Instructions and Grading Criteria. Write a python program that will use looping constructs as noted in the assignment requirements. Name your program yourlastname_asgn5.py Assignment Requirements IMPORTANT: Follow the instructions below explicitly. Your program must be structured as I describe below. Write a Python...
This is for python coding First of all, you need to know what Natural Numbers are....
This is for python coding First of all, you need to know what Natural Numbers are. They are the positive integers (whole numbers) 1, 2, 3, etc., and zero as well. For this project, there are TWO PORTIONS: PORTION 1: Write a program to find the SUM of the first n natural numbers the user wants to add. The program should first prompt the user for how many natural numbers are to be summed. The use for loop to do...
What is Sociology? What do sociologists do? What is your opinion of sociologists? Do you know...
What is Sociology? What do sociologists do? What is your opinion of sociologists? Do you know a sociologist? If so, who? Write Essay form.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT