Introduction to Programming in Swift 5 Coursera Quiz Answers

All Weeks Introduction to Programming in Swift 5 Coursera Quiz Answers

Welcome to Introduction to Programming in Swift 5.

In this course, we will introduce you to the absolute basics of the Swift programming language. Whether you are a brand new programmer or have experience with other programming languages this course is for you. Some of the things you will learn in this course are: • An Introduction to Swift 5 programming concepts

Enroll in Introduction to Programming in Swift 5 on Coursera

Introduction to Programming in Swift 5 Week 01 Quiz Answers

Quiz 1: Swift Experience

Q1. What is your level of experience with Swift?

  • I’ve heard of Swift, but have never used it.
  • I’ve dabbled in Swift, but now I’m serious about learning how to program!
  • I’ve used Swift before but need to update my knowledge.

Quiz 2: Variable Review

Q1. Explain the difference between variables and constants

  1. Variables should not start with numbers
  2. Constants means a number cannot be changed

Q2. When might a programmer choose to use a constant instead of a variable? What is an example use case.

If you use constant then the value cannot be changed

Quiz 3: String Review

Q1. Which of the following are acceptable ways to concatenate strings?

  • 1.let name = “Susan” + ” ” + “Smith”
  • 1.let make = “Toyota”
  • 2.let printCar = “\(make)” + ” Car”
  • 1.let first = “eggs”
  • 2.let second = “milk”
  • 3.let ingredients = “\(first) + \(second)”
  • 1.let first = “John”
  • 2.let middle = “Henry”
  • 3.let last = “Smith”
  • 4.let fullName = first.combine(middle).combine(last)

Quiz 4: Number Review

Q1. Given the following code, what is the Type of the result constant?

1.let first = 25.0

2.let second = 3

3.let result = Double(Int(first) * second)

  • This code will not compile
  • Float
  • Int

Introduction to Programming in Swift 5 Week 02 Quiz Answers

Quiz 1: Boolean Review

Q1. Given the code below, what is the value of the result constant?

1.var invalid = true

2.var valid = false

3.let result = invalid == valid

  • True
  • False

Quiz 2: Array Review

Q1. Given the code below, what will be the value of the result constant?

  1. let data = ["Red", "Blue", "Green"]

2. let result = data[3]

  • “Blue”
  • “Green”
  • This code will not compile
  • The code will compile, but will cause an error/crash at runtime

Quiz 3: Loops Review

Q1. When the code below is executed what will be the final value of the result variable?

  1. var result = 0 

2. for x in 0...11 {    

3. result += x

4. }

Enter Answers Here:    66

Introduction to Programming in Swift 5 Week 03 Quiz Answers

Quiz 1: Swift Language Assessment

Q1. When this code is executed, what will be the value of the t constant?

1.let t = 5
2.t = t + 5

  • 25
  • 5
  • 10
  • This code will not compile

Q2. When this code is executed, what will be the value of the result variable?

1.var result = “6”
2.result = result + “7”

Enter answer here: "67"

Q3. When this code is executed, what is the value of the item constant?

1.let items = [“Milk”, “Eggs”, “Bread”]
2.let item = items[1]

Enter answer here: "Eggs"

Q4. When this code compiles, what will the value of the constant fullName be?

1.var lastName: String?
2.
3.func getFullName(firstName: String) -> String {

  1. return firstName + ” ” + lastName!
  2. 5.}
  3. 6.
  4. 7.let fullName = getFullName(firstName: “John”)
  • The program will crash with an error: Cannot combine two strings using the + operator.
  • The program will crash with an error: Unexpectedly found nil while unwrapping an Optional value
  • “John “
  • “John (Optional)”

Q5. When this code is compiled, what will be the value of the area constant?

1.let length = 20.5
2.let width = 10
3.let area = length * width

  • 205
  • 205.50
  • 30.5
  • The program will not compile

Q6. Given the code below, what data type does the constant length have?

1.let length = 489.21

Enter answer here: Double

Q7. When this code is executed, what will the final value of the variable amount be?

1.var amount = 0
2.
3.for x in 0..<10 {

  1. if x % 2 == 0 {
  2. amount += 3
  3. }
  4. }
Enter answer here: 15

Q8. Given the code below, how can you access and store the last element in the array named planets?

1.let planets = [“Jupiter”, “Mars”, “Venus”, “Earth”]

  • let planet = planets[3]
  • let planet = planets.last!
  • let planet = planets.end
  • let planet = planets[planets.count – 1]

Q9. Given the code below, what will be the value of the result constant?

1.let result = true == false && false != true

  • true
  • false

Q10. When the code below is executed, what will be the value of the profile constant?

1.let firstName = “Amy”
2.let lastName = “Smith”
3.let age = 25
4.
5.let profile = “(firstName)(lastName)(age)”

Enter answer here: "AmySmith25"

Q11. When the code is executed below, what will be the value of the average constant?

  1. let average = Int(10.3 + 4.0) / 2
Enter answer here: 7

Q12. Which of the following are correct ways to modify an Array in Swift?

  • myArray.add(“new item”)
  • myArray.push(“new item”)
  • myArray.append(“new item”)
  • myArray.insert(“new item”, at: 0)

Q13. When the code below is executed, what will be the final value of the sum variable?

1.var sum = 0
2.for i in 0…20 {
3. sum += 1
4. }

Enter answer here: 21

Q14. When the code below is executed, what will be the value of the result constant?


1.var nicknames = [“jax” : “James”]
2.nicknames[“spike”] = “Tom”
3.nicknames[“jax”] = “Billy”
4.
5.let result = nicknames[“jax”]!

Enter answer here: "Billy!"

Q15. When the code below executes, what will be the final value of the result variable?\


1.var result = 0.0
2.
3.func calcPerimeter(sides: [Double], perimeter: Double) {
4. var perm = perimeter
5. for x in 0..<sides.count {
6. perm += sides[x]
7. }
8. }

10. calcPerimeter(sides:[5.0,2.0,3.1], perimeter: result)

Enter answer here: 3.1

Q16. Which of the following is correct syntax for conditional operations in Swift?


1.var result = false
2.if (result) { print(true) }


1.var result = false
2.if result { print(true) }

1.var result = false
2.if result
3.print(true)

1.var result = false
2.if result {
3. print(true)
4. }

1.var result = false
2.if result
3.{
4. print(true)
5.}

Q17. When the code is executed below, what will be the value of the result constant?


1.var isValid = false
2.let result = isValid ? 15 : 6

Enter answer here: 6

Q18. When the code is executed below, what will be the final value of the isValid variable?

1.var data: String?
2.var isValid = true
3.
4.func processata(someData: String?) {
5. guard let validData = someData else {
6. isValid = false
7. return
8. }
9. isValid = true
10. }

Enter answer here: false

Q19. When the code below is executed, what will be the value of the result constant?

  1. enum Device: Int {
  2. case iPhone
  3. case Android
  4. case MacBook
  5. case Windows
  6. }
  7. var chosen: Device = .MacBook
  8. let result = chosen.rawValue
  • 2
  • Device.MacBook
  • “MacBook”
  • 0
  • MacBook

Q20. When the code below is executed, what will be the value of the fullName variable?

1.var fullName = “empty”
2.var firstName: String?
3.var lastName: String?
4.
5.firstName = “Jan”

6.
7. if let first = firstName, let last = lastName {

  1. fullName = “(first) (last)”
  2. }
Enter answer here: "Jan"

Introduction to Programming in Swift 5 Week 04 Quiz Answers

Quiz 1: Swift Architecture Assessment

Q1. In Swift, inheritance is NOT possible when using a Struct

  • True
  • False

Q2. The acronym MVC stands for what?

  • Model View Controller
  • Model View-Model Controller
  • Mac Version Control
  • None of the above

Q3. When the code below is executed, what output will be printed?

1.class Person {

  1. func speak() {
  2. print(“Hello”)
  3. }
  4. }
  5. class Frenchman: Person {
  6. override func speak() {
  7. print(“Bonjour”)
  8. }
  9. }
  10. let jaque = Frenchman()
  11. jaque.speak()
Enter answer here: Bonjour

Q4. When the code below is executed, what output will be printed?

1.class Person{
2.var phrase = “”
3.func speak() {
4.phrase = “Hello”
5.}
6.}

7.class Italian: Person {
8.override func speak() {
9.super.speak()
10.phrase += ” Ciao”
11.print(phrase)
12. }
13. }
14.let vinny = Italian()
15.vinny.speak()

Enter answer here: Hello Ciao

Q5. What is true concerning the code below?


1.class Vehicle {
2.func info() {
3.print(“Vehicle”)
4. }
5. }

6.class Truck: Vehicle {
7.override func info() {
8.print(“Truck”)
9. }

10. }
11.let aTruck = Truck()

12.if let aVehicle = aTruck as? Vehicle { 

13.aVehicle.info()}

14. }

  • When executed, the word “Vehicle” will print to the console
  • The code will not even compile due to syntax errors
  • When executed, the code will run but will produce a runtime crash
  • When executed, nothing will print because the cast to Vehicle fails
  • When executed, the word “Truck” will print to the console
  • This is an example of polymorphism

Q6. When the code below is executed, what output will be printed?

1.struct Person {
2.var name: String
3.var age: Int
4. }
5.let john = Person(name: “John”, age: 21)
6.var steven = john
7.steven.name = “Steven”
8.print(john.name)

Enter answer here: John

Q7. When the code is executed below, what output will be printed?

1.lass Person {
2.var name: String
3.var age: Int
4.init(name: String, age: Int) {
5.self.name = name
6.self.age = age
7. }
8. }
9.let john = Person(name: “John”, age: 21)
10.var steven = john

11.steven.name = “Steven”

12.print(john.name)

Enter answer here: steven 

Q8. What purpose does the controller serve in Model View Controller?

  • It binds the data from the models into the views/UI of the application
  • It controls the data models including how they are retrieved and stored
  • It controls the entire application and should be accessible from any other place in that application
  • All of the above

Q9. What purpose does the view serve in Model View Controller

  • A controller is broken up into multiple views, which are data sets
  • A view is a representation of something a user can visually see in the application
  • A view represents only the main window of an application. Other visual elements are known as controllers
  • None of the above

Q10. When the code is executed below, what output will be printed?

1.class Humanoid {
2.func species() {
3.print(“Humanoid”)
4.}
5.}
6.class Orc: Humanoid {
7.func species() {
8.print(“Orc”)
9. }
10. }
11.class Elf: Humanoid {
12.func species() {
13.print(“Elf”)
14. }
15. }
16. class Urukhai: Orc, Elf {
17.func species() {
18.print(“Uruk-hai”)
19. }
20. }
21.let urukhai = Urukhai()
22.urukhai.species()

  • The word “Humanoid” will be printed
  • The words “Orc” and “Elf” will be printed in that order
  • The words “Elf” and “Orc” will be printed in that order
  • The word “Uruk-hai” will be printed
  • This code will not compile and therefore will never be executed
Introduction to Programming in Swift 5 Coursera Course Review:

In our experience, we suggest you enroll in the Introduction to Programming in Swift 5 Coursera Course and gain some new skills from Professionals completely free and we assure you will be worth it.

Introduction to Programming in Swift 5 course is available on Coursera for free, if you are stuck anywhere between quiz or graded assessment quiz, just visit Networking Funda to get Introduction to Programming in Swift 5 Coursera Quiz Answers.

Conclusion:

I hope this Introduction to Programming in Swift 5 Coursera Quiz Answers would be useful for you to learn something new from this Course. If it helped you then don’t forget to bookmark our site for more Coursera Quiz Answers.

This course is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisite courses.

Keep Learning!

Get all Course Quiz Answers of Swift 5 iOS Application Developer Specialization

Introduction to Programming in Swift 5 Coursera Quiz Answers

Introduction to iOS App Development with Swift 5 Quiz Answers

Tables, Data & Networking in iOS Coursera Quiz Answers

iOS App Store & In-App Purchases Coursera Quiz Answers

Leave a Reply

error: Content is protected !!