Please answer questions P5.8 &P5.6 Write a function def countwords (string) that
ID: 3685692 • Letter: P
Question
Please answer questions P5.8 &P5.6
Write a function def countwords (string) that returns a count of all words in the string string. Vowels are the letters a, e, I, o, and u, and their uppercase variants. Write a function def countwords (string) that returns a count of all words in the string string. Words are separated by spaces. For example, countwords ("Mary had a little lamb") should return 5. It is a well-known phenomenon that most people are easily able to read a text whose words have two characters flipped, provided the first and last letter of each word are not changed. For example, I dn'ot give a dman for a man that can only spell a word one way. (Mark Taiwn) Write a function scramble e(word) that constructs a scrambled version of a given word, randomly flipping two characters other than the first and last one. Then write a program that reads words and prints the scrambled words. Write functions def sphereVolume (r) def SphereSurface (r) def CylinderVolume (r, h) def CylinderSurface(r, h) def cone Volume(r, h) def coneSurface (r, h) that compute the volume and surface area of a sphere with radius r, a cylinder with a circular base with radius r and heights h, and a cone with a circular base with radius r and height h. Then write a program that prompts the user for the values of r and h, calls the six functions, and prints the results. Write a function def readFloat(prompt) that displays the prompt string, followed by a space, reads a floating-point number in, and returns it. Here is a typical usage: salary = readFloat ("Please enter your salary:") percentageRaise = readFloat ("What percentage raise would you like?") Enhance the intName function so that it works correctly for valuesExplanation / Answer
P5.8P5
# IMPORTS
from random import randint
# FUNCTIONS
def scramble(word):
result = word[0]
if len(word) > 1:
for i in range(len(word) - 2, 0, -1):
result += word[i]
result += word[len(word) - 1]
return result
def main():
print("I don't give a damn for a man that can only spell a word one way.")
print("Scrambled....")
print(scramble("I"), scramble("don't"), scramble("give"), scramble("a"), scramble("damn"), scramble("for"),
scramble("a"), scramble("man"), scramble("that"), scramble("can"), scramble("only"), scramble("spell"),
scramble("a"), scramble("word"), scramble("one"), scramble("way"))
# PROGRAM RUN
main()
P5.6
def countVowels(string):
countVowels = 0
vowels = ("a", "e", "i", "o", "u", "A", "E", "I", "O", "U")
for i in range(len(string)):
if string[i] in vowels:
countVowels += 1
return countVowels
def main():
string = str(input("Enter a word"))
print("number of vowels are", countVowels(string))
main()