1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Luden [163]
2 years ago
10

Write a function named count_vowels that accepts two arguments: a string and an empty dictionary. The function should count the

number of times each vowel (the letters a, e, i, o, and u) appears in the string, and use the dictionary to store those counts. When the function ends, the dictionary should have exactly 5 elements. In each element, the key will be a vowel (lowercase) and the value will be the number of times the vowel appears in the string. For example, if the string argument is 'Now is the time', the function will store the following elements in the dictionary: 'a': 0 • 'e': 2 'i': 2 'o': 1 'u': 0 The function should not return a value.
Computers and Technology
1 answer:
SpyIntel [72]2 years ago
7 0

The function that counts the number of times a vowel exist in a string is as follows:

def count_vowels(string, dictionary):

    vowels = 'aeiou'

    dictionary = {}.fromkeys(vowels, 0)

    for i in string:

         if i in vowels:

              dictionary[i] += 1

    return dictionary

print(count_vowels("trouble", {}))

<h3>Code explanation.</h3>

The code is written in python.

  • we defined a function named "count_vowels". The function accept a string and an empty dictionary.
  • Then. we store the vowels in a variable vowels.
  • The dictionary is used to store the key value pair i.e the vowels and the number of times they appear.
  • We looped through the string.
  • If any value in the string is in vowels,  we increase the dictionary values by 1.
  • Then, we return the dictionary.
  • Finally, we call the function with it parameters.

learn more on function here: brainly.com/question/27219031

You might be interested in
In the context of this passage, which of the following is a synonym for alleged? A intended B claimed C denied D revealed
Zinaida [17]
B. Claimed

Alleged means somebody CLAIMED that you did something. So, you're being accused of doing something that you may have not done. I hope this helps! :)
7 0
3 years ago
What are the data type(s) will be used to declare the variable(s) needed to
postnew [5]
The three primitive data types used in this course are int (integer numbers), double (decimal numbers), and boolean (true or false). Each variable has associated memory that is used to hold its value.
4 0
3 years ago
The function below takes two numeric parameters. The first parameter specifies the number of hours a person worked and the secon
Triss [41]

Answer:

def calculate_pay(total_worked_hours, rate_per_hour):

   if total_worked_hours > 40:

       return (40 * rate_per_hour) + ((total_worked_hours - 40) * 2 * rate_per_hour)

   else:

       return total_worked_hours * rate_per_hour

Explanation:

  • Create the calculate_pay function that takes 2 parameters.
  • Inside the function check whether the total_worked_hours is greater than 40 and then return the pay by calculating with the help of formula for work over 40 hours.
  • Otherwise return the pay by multiplying the total_worked_hours with rate_per_hour.
6 0
4 years ago
What are two examples of ways an electronic record may be distributed to others?
Karolina [17]

Answer:

Way 1. Email, Way 2. Publish on Internet

Explanation:

8 0
3 years ago
What is one effective way for employees to keep their skill-sets current
natta225 [31]
Is it a multiple choice answer? if so would like to see the answers as there are TONS of effective ways and if i list one it may not be in that list you have if its multiple choice.
3 0
3 years ago
Other questions:
  • Which is the lowest Complexity"
    15·1 answer
  • In 2007, __________ Floridians were injured in alcohol-related collisions.
    6·2 answers
  • _____ are independent and not associated with the marketing efforts of any particular company or brand.​
    9·1 answer
  • Number of frames displayed per second
    15·1 answer
  • _______ allows you to add formatting such as shapes and colors to text.
    14·1 answer
  • Create a dynamic array of 100 integer values named myNums. Use a pointer variable (like ptr) which points to this array. Use thi
    6·1 answer
  • 25 Points Asap <br> Write a Java program named Light.java that displays a light bulb shown below:
    14·1 answer
  • Which is a concept of the CIA of Computer Security
    7·1 answer
  • What is 1 st genaration of computer ​
    14·2 answers
  • Write a Boolean expression that tests if the value stored in the variable num1 is equal to the value stored in the variable num2
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!