Question
PLEASE ANSWER ALL PARTS! Questions for Swift a) Assume you have a dictionary of names and ages as follows: let data = [Chris P. Bacon:
PLEASE ANSWER ALL PARTS! Questions for Swift
a) Assume you have a dictionary of names and ages as follows:
let data = [Chris P. Bacon: 32, Barb E. Dahl: 41, Carrie Oakey: 14]
Write a loop that will iterate over the data and print each name/age pair in a sentence such as : Noah Lott is 5 years old.
b) Write a while loop (or a repeat/while loop) that will print the odd numbers from 1 to N inclusive.
c) What is the purpose of Thread.sleep()?
d) What is the output of the following code?
let lowHR = 110 let highHR = 125 var movementHeartRates: [String: Int] =
["Walking": 85, "Running": 120, "Swimming": 130, "Cycling": 128, "Skiing": 114, "Climbing": 129]
for (movement, heartRate) in movementHeartRates { if heartRate > lowHR && heartRate < highHR {
continue
}
print("You should avoid \(movement).")
}
e) Assume you have a String called letters that could contain any word or set of letters. For example: let letters = BCDE Write a loop that will print each letter in the string in a sentence on its own line.
For example:
The letter is B
The letter is C
The letter is D
The letter is E
f) Write a for loop that will print the names in a String array (called names) in reverse order starting with the last element.
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