Write a program with a user defined program with string as a parameter which replaces all vowels in the string with '*'.
Answers
Answer:
1. Write a program that performs the following operations on a string:
(a) Prompt the user to input a string.
(b) Extract all the digits from the string.
(c) If there are digits in the inputted string:
• Calculate and display the sum of digit.
• Also display:
▪ The original string
▪ The digits
▪ The sum of the digits
(d) If there are no digits:
• Display the original string along with an appropriate message as “No Digits are present”
Ans. str1 = input("Enter the string: ")
sum = 0
num = 0
if str1.isalpha() == False:
for i in str1:
if i.isdigit() == True:
num =num*10 + int(i)
sum += int(i)
print("Original String: ",str1)
print("Digits: ",num)
print("Sum of digits is: ",sum)
else:
print("Original String: ", str1, "has no digit")
2. Write a program with a user-defined function with string as a parameter which replaces all vowels in the
string with ‘*’.
Ans. #Function to replace all vowels in the string with '*'
def replaceVowel(st):
#Create an empty string
newstr = ''
for character in st:
#Check if next character is a vowel
if character in 'aeiouAEIOU':
#Replace vowel with *
newstr += '*'
else:
newstr += character
return newstr
#End of function
st = input("Enter a String: ")
st1 = replaceVowel(st)
print("The original String is:", st)
Computer Science with Python–XII 3.8 1. Write a user-defined function to calculate the area of a triangle.
print("The modified String is:", st1)
Explanation:
please mark my answer as brainliest answer
Answer:
Mark above answer has brainlist
joh-eun halu doeseyo