Question

In: Computer Science

<Python coding question string practice> Can anyone please answer these python string questions?? 1. Write a...

<Python coding question string practice>

Can anyone please answer these python string questions??

1. Write a function called username that takes as parameters a person's first and last names and prints out his or her username formatted as the last name followed by an underscore and the first initial. For example, username("Martin", "freeman") should print the string "freeman_m".

2. Write a function called letters that takes as a parameter a string and prints out the characters of the string, one per line. For example letters("abc") should print

a

b

c

3. Write a function called backward that takes as a parameter a string and prints out the characters of the string in reverse order, one per line. For example backward("abc") should print

c

b

a

4. Write a function called noVowels that takes as a parameter a string and returns the string with all the vowels removed. For example, noVowels("this is an example.") should return "the s n xmpl.".

Solutions

Expert Solution

Here is the completed code for this problem including code for testing. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

Note: Please maintain proper code spacing (indentation), just copy the code part and paste it in your compiler/IDE directly, no modifications required.

#method taking first and last names and prints username formatted
# as the last name followed by an underscore and the first initial

def username(first, last):
    #concatenating lastname and underscore and first letter of first name and
    #converting the resultant string to lower case & printing it
   
print((last+'_'+first[0]).lower())

#method to print characters in a text one by one
def letters(text):
    #simply looping through text and printing each character
   
for c in text:
        print(c)

#method to print characters in a text one by one in reverse
def backward(text):
    #looping from i=0 to i=len(text)-1
   
for i in range(len(text)):
        #printing ith character from back
       
print(text[len(text)-1-i])

#method to return a string with all the vowels removed from parameter string
def noVowels(text):
    result=''
   
for c in text:
        #converting c to lowercase and if it is not in the string aeiou, appending to result
       
if c.lower() not in 'aeiou':
            result+=c
   #returning result
   
return result


#testing all methods

#getting first and last name, testing username method

first=input("Enter first name: ")
last=input("Enter last name: ")
username(first,last)

#reading another text
text=input("Enter some text: ")

#testing letters method
print("Printing letters forward")
letters(text)

#testing backward method, using same text
print("Printing letters backward")
backward(text)

#testing noVowels method, using same text
print("Removing vowels from text")
print(noVowels(text))

#output



Related Solutions

This is Python coding question, and topic is loop Can anyone help me figuring these out?...
This is Python coding question, and topic is loop Can anyone help me figuring these out? (Please do not use build in function) Thanks. 1. Write a program that prints your name 100 times to the screen. 2. Write a program that takes a string s and an integer n as parameters and prints the string s a total of in n times(once per line) 3. Write a for loop that prints all the integers from 3141 to 5926, skipping...
Please answer these questions in as long of detail as possible. Question 1 a) Write the...
Please answer these questions in as long of detail as possible. Question 1 a) Write the expression used to calculate rate of digestion as it’s related to starch concentration and time: b) Explain what a catalytic process is and how it is different from the non-catalytic version of the process. Give an example of an enzymatic process other than amylase and describe the substrate(s)/product(s): c) Describe what the enzyme amylase does and what would happen in the absence of this...
Using python as the coding language please write the code for the following problem. Write a...
Using python as the coding language please write the code for the following problem. Write a function called provenance that takes two string arguments and returns another string depending on the values of the arguments according to the table below. This function is based on the geologic practice of determining the distance of a sedimentary rock from the source of its component grains by grain size and smoothness. First Argument Value Second Argument Value Return Value "coarse" "rounded" "intermediate" "coarse"...
please answer this in a simple python code 1. Write a Python program to construct the...
please answer this in a simple python code 1. Write a Python program to construct the following pattern (with alphabets in the reverse order). It will print the following if input is 5 that is, print z one time, y two times … v five times. The maximum value of n is 26. z yy xxx wwww vvvvvv
Python please Questions #6 and # 7 please A string is one of most powerful data...
Python please Questions #6 and # 7 please A string is one of most powerful data types in programming. A string object is a sequence of characters and because it is a sequence, it is indexable, using index numbers starting with 0. Similar to a list object, a string object allows for the use of negative index with -1 representing the index of the last character in the sequence. Accessing a string object with an invalid index will result in...
Python please Questions #3, #4 and # 5 please A string is one of most powerful...
Python please Questions #3, #4 and # 5 please A string is one of most powerful data types in programming. A string object is a sequence of characters and because it is a sequence, it is indexable, using index numbers starting with 0. Similar to a list object, a string object allows for the use of negative index with -1 representing the index of the last character in the sequence. Accessing a string object with an invalid index will result...
Python please Write a function that takes a string as an argument checks whether it is...
Python please Write a function that takes a string as an argument checks whether it is a palindrome. A palindrome is a word that is the same spelt forwards or backwards. Use similar naming style e.g. name_pal. E.g. If we call the function as abc_pal(‘jason’) we should get FALSE and if we call it a abc_pal(‘pop’) we should get TRUE. Hint: define your function as abc_pal(str). This indicates that string will be passed. Next create two empty lists L1=[] and...
I will rate life saver to anyone who can answer these short questions for me! 1....
I will rate life saver to anyone who can answer these short questions for me! 1. Provide a molecular/microscopic interpretation of heat flow or heating, and work. 2. Explain why U of an ideal gas is only dependent on T, and independent on V and P, and show that CP - CV = nR for an ideal gas. 3. When 229 J of energy is supplied as heat at constant pressure to 3.00 mol CO2(g), the temperature of the sample...
can anyone provide the PN VATI FUNDAMENTALS questions with answers please?
can anyone provide the PN VATI FUNDAMENTALS questions with answers please?
Hi can anyone answer these for me before 12am tonight please! 1. Not only are you...
Hi can anyone answer these for me before 12am tonight please! 1. Not only are you a brilliant accountant, you also have a knack for technology. Over time you’ve been developing an idea for an internet search engine and email service that would make the founders of Google green with envy. You’ve begun offering this service for free to everyone, but to start earning revenues you’ve had to spend a lot of money on advertising. Because of this, you need...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT