Computer Science
Write a program to count the number of times a character appears in a given string.
Python
Python Dictionaries
10 Likes
Answer
str = input("Enter the string: ")
ch = input("Enter the character to count: ");
c = str.count(ch)
print("Count of character",ch,"in",str,"is :", c)
Output
Enter the string: appoggiatura
Enter the character to count: a
Count of character a in appoggiatura is : 3
Answered By
7 Likes
Related Questions
Fill in the blanks of the following code so that the values and keys of dictionary d are inverted to create dictionary fd.
d = {'a':1, 'b':2, 'c':3} print(d) fd = {} for key, value in d.____(): fd[____] = ____ print(fd)
Write a program to enter names of employees and their salaries as input and store them in a dictionary.
Write a program to convert a number entered by the user into its corresponding number in words. For example, if the input is 876 then the output should be 'Eight Seven Six'.
(Hint. use dictionary for keys 0-9 and their values as equivalent words.)Repeatedly ask the user to enter a team name and how many games the team has won and how many they lost. Store this information in a dictionary where the keys are the team names and the values are lists of the form [wins, losses].
(a) Using the dictionary created above, allow the user to enter a team name and print out the team's winning percentage.
(b) Using the dictionary, create a list whose entries are the number of wins of each team.
(c) Using the dictionary, create a list of all those teams that have winning records.