Page 1 of 1

USE PYTHON !!

Posted: Mon Jun 06, 2022 4:54 pm
by answerhappygod
USE PYTHON !!
Use Python 1
Use Python 1 (99.95 KiB) Viewed 30 times
1. Write a function print_squares (values) that takes as a parameter a list of numbers called values, and uses an element-based loop to compute and print out the square of each value. Here are some examples: >>> print_squares([6,7,8]) 36 49 64 >>> print_squares([1.2, 2.5]) 1.44 6.25 2. Write a function print_multiples(n, m) that will print out the first m multiples of the integer n, one per line. Here are some examples: >>> print_multiples(2, 10) # print the first 10 multiples of 2 0 2 4 6 8 10 12 14 16 18

>>> print_multiples (12, 5) # print the first 5 multiples of 12 0 12 24 36 48 Your function must use the definite loop with the built-in range function to control the number of repetitions. Inside the loop, use the multiplication operator to calculate the multiple and print it out. 3. Write the function num_vowels (s), which will process a string s and return the number of vowels (letters that are in the string aeiou) in that string. For example: >>> num_vowels('chocolate') 4 >>> num_vowels('chocolate therapy ice cream') 10 Your function must use a definite loop to process the string, and the accumulator pattern to build the count of vowels. Hints: ▪ You may choose whether to solve this problem using an element-based loop or an index-based loop. It can be solved it each way, but be careful not to mix-and- match!