Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem Set 3 Note: Use the variable names defined in the instructions for each problem. Failure to do so will result in a loss of
Problem Set
Note:
Use the variable names defined in the instructions for each problem. Failure to do so will result in a loss of points.
You need to use code to arrive at a solution. Hard coding a solution results in points for the problem.
Use only syntax covered in the Units so far. Using any other syntax results in points for the problem.
Problem
In the cell below, write code that iterates over the string myStr and does the following:
Print each character.
Count the number of characters and stores the result the variable cntChars. Do not use any functions to count.
Print the variable myStr and cntChars with an appropriate label as shown below in Expected Output.
myStr "MICHIGAN"
# Write your code below.
myStr "MICHIGAN"
# Write your code below.
Expected Output:
M
I
C
H
I
G
A
N
The number of characters in MICHIGAN is
Problem
In the cell below, write one loop that iterates over the list mixedList and does the following:
Prints each element and the element type.
Count the number of elements and store the result in the variable cntList. Do not use any function to count.
Print cntList preceded by an appropriate label as shown below.
mixedList hello "the end",
# Write your code below.
Expected Output:
hello
class 'int'
class 'int'
class 'float'
class 'float'
class 'int'
the end class str
class str
class 'int'
The number of elements in the list is
Problem
Write code that iterates over to the string sentence and does the following:
Count the number of characters using the variable numChars.
Count the number of vowels using the variable numVowels. A character is a vowel if it is a member of the tuple vowels.
Print the variables numChars and numVowels preceded by appropriate labels as shown below.
Do NOT use the a function to solve the problem. You may use the len function on the string to confirm the your answer is correct.
sentence "The quick brown rhino jumped over the extremely lazy fox."
vowels aeiou
# Write your code below.
Expected Output:
The number of characters is
The number of vowels is
Problem
Write code in the cell below that does the following:
Create a list called words from the words in the string sentence.
Iterate over words
Add to a list called wordLens which contains the length of the current word.
Count the current word using the variable numWords. Do not use a function.
Print the word and the word length.
Print numWords as shown in expected output.
Print the list wordLens.
You need one loop to solve this problem. You may use the len and split functions.
sentence "The quick brown rhino jumped over the extremely lazy fox"
# Write your code below.
Expected Output:
The
quick
brown
rhino
jumped
over
the
extremely
lazy
fox
Number of words is
Problem
The string addStr contains list of numbers separated by the plus sign. Write code that uses an accumulation pattern to take the sum of all numbers and assigns it to the variable sumVal. Print the variable sumVal prefixed by an appropriate label.
You may use the split function to split by and int function to cast to an integer.
addStr
# Write your code below.
Expected Output:
The total of all numbers is
Problem
The string weekTemps contains a commaseparated list of fahrenheit temperatures. Write code that does the following:
Finds the minimum temperature in fahrenheit and stores the result in minTempF.
Computes the average temperature in fahrenheit and stores the result in avgTempF.
Convert the minimum and average temperature in fahrenheit to celsius and stores the results in minTempC and avgTempC respectively. Do not hard code your answer. This means that your code must compute both the total of all temperatures and the number of temperatures in weekTemps.
Do the following:
Split the string on and store the resultant list in a variable
Iterate over that variable:
Apply a count pattern to count the number of temps.
Apply an accumulation pattern to total the temperature values.
if the current temperature is smaller than minTempF:
Replace the contents of minTempF with the current temperature.
Compute the average temperature and store the result in avgTempF.
Print avgTempF and minTempF as shown in the expected output. Note, you will do some additional work to produce the expected output.
Convert avgTempF to celsius and store the result in avgTempC.
Convert minTempF to celsius and store the result in minTempC.
Print both variables as shown in the expected output.
The average temperature is defined as the total of all temperatures divided by the number of temperatures.
To convert from fahrenheit: temperature in celsius temperature in fahrenheit
You
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started