Learn to Program: The Fundamentals Coursera Quiz Answers

Get Learn to Program: The Fundamentals Coursera Quiz Answers

Behind every mouse click and touch-screen tap, there is a computer program that makes things happen. This course introduces the fundamental building blocks of programming and teaches you how to write fun and useful programs using the Python language.

Enroll on Coursera

Learn to Program: The Fundamentals Coursera Quiz Answers

Week 1: Python, Variables, and Functions

Q1. Read the description given by

1 help(round)

Then select the function call(s) below that run without error. You can check your answers by running the code in the Python Shell.

  • round(45.345, 2)
  • round()
  • round(45.8)
  • round(45.345, 2, 5)
  • round(45)

Q2. What type of value does built-in function \color{black}{\verb|id|}id return? Determine the answer using the description given by

1 help(id)
  • int
  • float

Q3. Consider this code:

1 x = 8 / 4

What value does \color{black}{\verb|x|}x refer to?

 Answer: 2 

Q4. Consider this code:

1 x = 8 // 4


What value does \color{black}{\verb|x|}x refer to?

Enter answer here

Q5. Consider this code:

1 x = 3
2 y = 5
3 x = y

After the code above has executed, what value does \color{black}{\verb|x|}x refer?

Enter answer here

Q6. Consider this code:

1 x = 3
2 y = 5
3 x = y

After the code above has executed, what value does \color{black}{\verb|y|}y refer?

Enter answer here

Q7. Consider this code:

1 apple = banana

When the code above is executed, what type of error occurs?

  • NameError
  • SyntaxError

Q8. Consider this code:

1 def f(data):
2 return data * 0.5


Select the phrase that describes \color{black}{\verb|data|}data.

  • a parameter
  • an argument
  • a function name

Q9. Consider this code:

1 def example(a, b, c):
2 d = a + b - c
3 return d

How many parameters does function \color{black}{\verb|example|}example have?

  • 2
  • 1
  • 0
  • 3

Q10. Consider this code:

1 data = 3
2 data2 = 7.5
3 result = min(data, data2)

Select the phrase that describes \color{black}{\verb|data|}data in the third line.

  • an argument
  • a parameter
  • a function name

Q11. Consider this code:

1 round(45.342)

What value does the expression above produce?

Enter answer here

Q12. Consider this code:

1 def even_bigger(x):
2 return (2 * x) ** x
3
4 even_bigger(12)

Which value does \color{black}{\verb|even_bigger(12)|}even_bigger(12) produce?

  • 2481152873203736576
  • 584318301411328
  • 10240000000000
  • 36520347436056576

Week 2: Strings and Designing Functions

Q1. Which of the following results in a syntax error?

1 "yes
2 no"
1 '''yesno'''
1 'yes\nno'
1 'yes
2 no'

Q2. Which of the following results in a syntax error?

1 '"Once upon a time…", she said.'
1 "He said, "Yes!""
1 '3\'
1 ''That's okay'''

Q3. The following is printed by a \color{black}{\verb|print|}print function call:

1 yesterday
2 today
3 tomorrow

Select the function call(s) that prints what is shown above.

1 print('yesterday\ntoday\ntomorrow')
1 print('''yesterday
2 today
3 tomorrow''')
1 print('yesterday
2 today
3 tomorrow')
1 print('''yesterday
2 \ntoday
3 \ntomorrow''')

Q4. The following is printed by a print function call:

1 hello-how-are-you

Select the function call(s) that prints what is shown above.

  • print(’hello’, ’how’, ’are’, ’you’ + ’-’ * 4)
  • print(’hello-’ + ’how-are-you’)
  • print(’hello’ + ’-’ + ’how’ + ’-’ + ’are’ + ’-’ + ’you’)
  • print(’hello’, ’how’, ’are’, ’you’)
  • print(’hello’, ’-’, ’how’, ’-’, ’are’, ’-’, ’you’)

Q5. Consider this code fragment:

1 >>> def announce_location(country):
2 # Missing function body
3 >>> instructor_location = announce_location('Canada')
4 >>> print(instructor_location)
5 Canada

Select the missing function body from the options below.

  • return country
  • return instructor_location
  • print(country)
  • print(’Canada’)

Q6. Consider this code fragment:

1 >>> def announce_location(country):
2 # Missing function body
3
4 >>> instructor_location = announce_location('Canada')
5 Canada
6 >>> print(instructor_location)
7 Canada

Select the missing function body from the options below.

  • return country
  • print(country)
  • return country
  • print(country)
  • return country
  • print(country)

Q7. Consider the following statements:

1 x = None
2 print(x)

What is printed when the code above executes?

Enter answer here

Q8. What is the first step of the Design Recipe?

  • Test
  • Examples
  • Type Contract
  • Code

Q9. What is the last step of the Design Recipe?

  • Type Contract
  • Code
  • Test
  • Examples

Q10. What is the Type Contract for the following function definition?

1 def is_passing_grade(grade):
2 """Return 'pass' if grade is at least 50 and return 'fail' otherwise.
3 >>> is_passing_grade(45)
4 'fail'
5 >>> is_passing_grade(80.5)
6 'pass'
7 """
  • (number) -> str
  • (int) -> str
  • (float) -> str
  • (int, float) -> str

Q11. What is the Type Contract for the following function definition?

1 def total_vowels(word1, word2):
2 """Return the number of vowels in words word1 and word2.
3 >>> total_vowels('hello', 'hi')
4 3
5 """
  • (str, str) -> int
  • (str, str) -> float
  • (int) -> str, str
  • str == int

Q12. According to the Description of function \color{black}{\verb|get_oldest|}get_oldest, what value should be returned by the Example function call?

1 def get_oldest(age1, age2):
2 ''' (int, int) -> int
3
4 Return the oldest of the two ages, age1 and age2.
5
6 >>> get_oldest(27, 22)
7 ???
8 '''
Enter answer here

Q13. Here is an insufficient docstring for function \color{black}{\verb|euro_to_dollars|}euro_to_dollars:

1 def euro_to_dollars(amount):
2 """(number) -> number
3
4 Calculate the value in Canadian dollars of the given quantity of Euros.
5 """
  • Identify the problem(s) with the Description in the docstring above.
  • It doesn’t explain which Python operators are used to perform the calculation.
  • It doesn’t say what the function returns.
  • It doesn’t mention the parameter types.
  • It doesn’t mention the parameters by name.

Q14. Two function definitions are saved in the same file:

A function \color{black}{\verb|count_vowels|}count_vowels has one parameter, a word, and returns the number of vowels in that word.

A function \color{black}{\verb|count_consonants|}count_consonants has one parameter, a word, and returns the number of consonants in that word.

To determine the number of letters in a word, write a one-line body for the following function that calls both \color{black}{\verb|count_vowels|}count_vowels and \color{black}{\verb|count_consonants|}count_consonants:

1 def count_letters(word):
2 """ (str) -> int
3
4 Return the number of letters in word.
5 >>> count_letters('hello')
6 5
7 >>> count_letters('bonjour')
8 7
9 """
# Write the one-line function body that belongs here.

Note:

do not call any functions other than those listed above

do not use any unnecessary parentheses

Enter answer here

Q15. Two function definitions are saved in the same file:

A function get_capital has one string parameter that represents a country and returns its capital.

A function longer has two string parameters and returns the longer of the two strings.

Variables country1 and country2 refer to str values. Write a one-line expression that produces the longer of the capitals of country1 and country2. Your expression should involve calls on both \color{black}{\verb|get_capital|}get_capital and \color{black}{\verb|longer|}longer.

Note:

do not call any functions other than those listed above

do not use any unnecessary parentheses

Enter answer here

Q16. What is the value of \color{black}{\verb|average|}average after the following code is executed?

1 grade1 = 80
2 grade2 = 90
3 average = (grade1 + grade2) / 2
4 grade1 = 100
  • 85.0
  • 85
  • 95.0
  • 95

Q17. Below is an image of the Python Visualizer in action. The line with the red arrow (line 15) is about to be executed. When we press Forward, function convert_to_minutes will be called, control will move to line 11 of the code (the first line of that function), and a new stack frame will be created containing variable \color{black}{\verb|num_hours|}num_hours. What value will \color{black}{\verb|num_hours|}num_hours refer to then? (We are looking for a value, not a memory address.)

(If the image is too small, right-click on it and open it in a new browser tab. Then you can zoom in.)

Enter answer here

Q18. The line with the red arrow (line 15) is about to be executed. After stepping through to the end of the code below (we can do this by pressing the Last button), how many variables (excluding those that refer to functions) will be on the stack? Recall that the stack is represented by the images on the left-hand side of the model. (If the image is too small, right-click on it and open it in a new browser tab. Then you can zoom in.)

  • 1
  • 2
  • 3
  • 4
  • 5
Learn to Program: The Fundamentals Course Review:

In our experience, we suggest you enroll in Learn to Program: The Fundamentals courses and gain some new skills from Professionals completely free and we assure you will be worth it.

Learn to Program: The Fundamentals course is available on Coursera for free, if you are stuck anywhere between a quiz or a graded assessment quiz, just visit Networking Funda to get Learn to Program: The Fundamentals Quiz Answers.

Conclusion:

I hope this Learn to Program: The Fundamentals 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 Quiz Answers.

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

Keep Learning!

Leave a Reply

error: Content is protected !!