this is a homework question i am currently stuck on for my computing class. I have no experience with python before and this is my first months of using it. The assignment i am currently stuck on is this
-Write a program underscores.py that inputs a phrase from the user and prints out the phrase with the white space between words replaced by an underscore. For instance if the input is "the best one", then it would print the_best_one. The conversion can be done in only one or two statements using the recent string methods.
Online Tutorial Section 220.127.116.11, Acronym Exercise (Extra Credit, also 10 points)
An acronym is a string of capital letters formed by taking the first letters from a phrase. For example, SADD is an acronym for ‘students against drunk driving’. Note that the acronym should be composed of all capital letters even if the original words are not. Write a program acronym.py that has the user input a phrase (string) and then prints the corresponding acronym.
To get you started, here are some things you will need to do. First check that you understand the basic syntax to accomplish the different individual tasks: indicating the proper syntax using a Python function or operation will allow you to accomplish each task. Invent appropriate variable names for the different parts. This is not a complete set of instructions! The idea is to make sure you know the basic syntax to use in all these situations. See the questions after the list to help you put together the final program.
• Get the phrase (a string) from the user.
• Convert the phrase to upper case.
• Divide the phrase into words by creating a list of those words.
• Create a new empty list, letters. (Alternatively, this can be an empty string.)
• Go through the list created in #3 with a for loop, and get the first letter of each word.
• Append that first letter to the list letters. (Or, concatenate it to the string letters.)
• Join the letters together, with no space between them. (Skip this if letters is a string.)
• Print the acronym.
This is what I tried so far, but it separates every letter and not each word
- Code: Select all
phrase = input("Please Enter a Phrase: " )