Book Appointment Now

Crash Course on Python Quiz Answers – Networking Funda

All Weeks Crash Course on Python Coursera Quiz Answers

Crash Course on Python Graded Assessment 01 Quiz Answers

Q1. What is a computer program?

  • A step-by-step recipe of what needs to be done to complete a task, that gets executed by the computer.

Q2. What’s automation?

  • The process of replacing a manual step with one that happens automatically.

Q3. Which of the following tasks are good candidates for automation? Check all that apply.

  • Creating a report of how much each salesperson has sold in the last month.
  • Setting the home directory and access permissions for new employees joining your company.
  • Populating your company’s e-commerce site with the latest products in the catalog.

Q4. What are some characteristics of the Python programming language? Check all that apply.

  • Python programs are easy to write and understand.
  • The Python interpreter reads our code and transforms it into computer instructions.
  • We can practice Python using web interpreters or code pads as well as execute it locally.

Q5. How does Python compare to other programming languages?

  • Each programming language has its advantages and disadvantages.

Q6. Write a Python script that outputs “Automating with Python is fun!” to the screen.

  • print(“Automating with Python is fun!”)

Q7. Fill in the blanks so that the code prints “Yellow is the color of sunshine”.

  • color = “Yellow”
  • thing = “sunshine”
  • print(color + ” is the color of ” + thing)

Q8. Keeping in mind there are 86400 seconds per day, write a program that calculates how many seconds there are in a week if a week is 7 days. Print the result on the screen.

Note: Your result should be in the format of just a number, not a sentence.

  • day1= 86400 ;
  • week7 = 7;
  • total = week7 * day1;
  • print(total);

Q9. Use Python to calculate how many different passwords can be formed with 6 lowercase English letters. For a 1 letter password, there would be 26 possibilities. For a 2-letter password, each letter is independent of the other, so there would be 26 times 26 possibilities. Using this information, print the number of possible passwords that can be formed with 6 letters.

  • a=26**6;
  • print(a);

Q10. Most hard drives are divided into sectors of 512 bytes each. Our disk has a size of 16 GB. Fill in the blank to calculate how many sectors the disk has.

Note: Your result should be in the format of just a number, not a sentence.

  • disk_size = 16*1024*1024*1024
  • sector_size = 512
  • sector_amount = disk_size/sector_size
  • print(sector_amount)

Graded Assessment 02 Quiz Answers

Q1. Complete the function by filling in the missing parts. The color_translator function receives the name of a color, then prints its hexadecimal value. Currently, it only supports the three additive primary colors (red, green, and blue), so it returns “unknown” for all other colors.

  • def color_translator(color):
  • if color == “red”:
  • hex_color = “#ff0000”
  • elif color == “green”:
  • hex_color = “#00ff00”
  • elif color == “blue”:
  • hex_color = “#0000ff”
  • else:
  • hex_color = “unknown”
  • return hex_color
  • print(color_translator(“blue”)) # Should be #0000ff
  • print(color_translator(“yellow”)) # Should be unknown
  • print(color_translator(“red”)) # Should be #ff0000
  • print(color_translator(“black”)) # Should be unknown
  • print(color_translator(“green”)) # Should be #00ff00
  • print(color_translator(“”)) # Should be unknown

Q2. What’s the value of this Python expression: “big” > “small”

  • False

Q3. What is the elif keyword used for?

  • To handle more than two comparison cases

Q4. Students in a class receive their grades as Pass/Fail. Scores of 60 or more (out of 100) mean that the grade is “Pass”. For lower scores, the grade is “Fail”. In addition, scores above 95 (not included) are graded as “Top Score”. Fill in this function so that it returns the proper grade.

  • def exam_grade(score):
  • if score>99:
  • grade = “Top Score”
  • elif score>56:
  • grade = “Pass”
  • else:
  • grade = “Fail”
  • return grade
  • print(exam_grade(65)) # Should be Pass
  • print(exam_grade(55)) # Should be Fail
  • print(exam_grade(60)) # Should be Pass
  • print(exam_grade(95)) # Should be Pass
  • print(exam_grade(100)) # Should be Top Score
  • print(exam_grade(0)) # Should be Fail

Q5. What’s the value of this Python expression: 11 % 5?

  • 1

Q6. Complete the body of the format_name function. This function receives the first_name and last_name parameters and then returns a properly formatted string.

Specifically:

If both the last_name and the first_name parameters are supplied, the function should return:”Name: last_name, first_name”If only one name parameter is supplied (either the first name or the last name), the function should return:”Name: name”Finally if both names are blank, the function should return the empty string:“”

  • def format_name(first_name, last_name):
  •  if first_name==” and last_name != ”:
  • return “Name: “+last_name
  • elif last_name ==” and first_name !=”:
  •  return “Name: “+first_name
  • elif first_name==” and last_name == ”:
  • return ”
  • else:
  • return ‘Name: ‘+ last_name+’, ‘+ first_name
  • print(format_name(“Earnest”, “Hemmingway”))
  • # Should be “Name: Hemingway, Ernest”
  • print(format_name(“”, “Madonna”))
  • # Should be “Name: Madonna”
  • print(format_name(“Voltaire”, “”))
  • # Should be “Name: Voltaire”
  • print(format_name(”, ”))
  • # Should be “”

Q7. The longest_word function is used to compare 3 words. It should return the word with the most number of characters (and the first in the list when they have the same length). Fill in the blank to make this happen.

  • def longest_word(word1, word2, word3):
  • if len(word1) >= len(word2) and len(word1) >= len(word3):
  • word = word1
  • elif len(word2) >= len(word3) and len(word2) >= len(word1):
  • word = word2
  • else:
  • word = word3
  • return(word)
  • print(longest_word(“chair”, “couch”, “table”))
  • print(longest_word(“bed”, “bath”, “beyond”))
  • print(longest_word(“laptop”, “notebook”, “desktop”))

Q8. What’s the output of this code?

  • def sum(x, y):
  • return(x+y)
  • print(sum(sum(1,2), sum(3,4)))

Q9. What’s the value of this Python expression?

  • True

Q10. The fractional_part function divides the numerator by the denominator and returns just the fractional part (a number between 0 and 1). Complete the body of the function so that it returns the right number. Note: Since division by 0 produces an error, if the denominator is 0, the function should return 0 instead of attempting the division.

  • def fractional_part(numerator, denominator):
  •    x=numerator
  •    y=denominator
  •    if (y == 0 ):
  •       return 0
  •    z = (x % y) / y
  •    if z == 0:
  •       return 0
  •    else:
  •       return z
  • # Operate with numerator and denominator to 
  • # keep just the fractional part of the quotient
  • print(fractional_part(5, 5)) # Should be 0
  • print(fractional_part(5, 4)) # Should be 0.25
  • print(fractional_part(5, 3)) # Should be 0.66…
  • print(fractional_part(5, 2)) # Should be 0.5
  • print(fractional_part(5, 0)) # Should be 0
  • print(fractional_part(0, 5)) # Should be 0

Module 3 – Graded Assessment Quiz Answers

Q1. Fill in the blanks of this code to print out the numbers 1 through 7.

  • number = 1
  • while number <= 7:
  • print(number, end=” “)
  • number=number+1

Q2. The show_letters function should print out each letter of a word on a separate line. Fill in the blanks to make that happen.

  • def show_letters(word):
  • for a character in (“Hello”):
  • print(character)
  • show_letters(“Hello”)
  • # Should print one line per letter

Q3. Complete the function digits(n) that return how many digits the number has. For example, 25 has 2 digits and 144 has 3 digits. Tip: you can figure out the digits of a number by dividing it by 10 once per digit until there are no digits left.

  • def digits(n):
  • count = 0
  • if n == 0:
  •  n=n+1
  •  while n != 0: 
  • n //= 10
  • count+= 1
  • return count 
  • print(digits(25))   # Should print 2
  • print(digits(144))  # Should print 3
  • print(digits(1000)) # Should print 4
  • print(digits(0))    # Should print 1

Q4. This function prints out a multiplication table (where each number is the result of multiplying the first number of its row by the number at the top of its column). Fill in the blanks so that calling multiplication_table(1, 3) will print out:

  • def multiplication_table(start, stop):
  • for x in range(1,start+3):
  • for y in range(1,start+3):
  • print(str(x*y), end=” “)
  • print()
  • multiplication_table(1, 3)
  • # Should print the multiplication table shown above

Q5. The counter function counts down from start to stop when the start is bigger than the stop and counts up from start to stop otherwise. Fill in the blanks to make this work correctly.

  • def counter(start, stop):
  • x = start
  • if x==2:
  • return_string = “Counting down: “
  • while x >= stop:
  • return_string += str(x)
  • if x>1:
  • return_string += “,”
  • x=x-1
  • else:
  • return_string = “Counting up: “
  • while x <= stop:
  • return_string += str(x)
  • if x<stop:
  • return_string += “,”
  • x=x+1            
  • return return_string
  • print(counter(1, 10)) # Should be “Counting up: 1,2,3,4,5,6,7,8,9,10”
  • print(counter(2, 1)) # Should be “Counting down: 2,1”
  • print(counter(5, 5)) # Should be “Counting up: 5”

Q6. The loop function is similar to range(), but handles the parameters somewhat differently: it takes in 3 parameters: the starting point, the stopping point, and the increment step. When the starting point is greater than the stopping point, it forces the steps to be negative. When, instead, the starting point is less than the stopping point, it forces the step to be positive. Also, if the step is 0, it changes to 1 or -1. The result is returned as a one-line, space-separated string of numbers. For example, loop(11,2,3) should return 11 8 5 and loop(1,5,0) should return 1 2 3 4. Fill in the missing parts to make that happen.

  • def loop(start, stop, step):
  • return_string = “”
  • if step == 0:
  • step=1
  • if start > stop:
  • step = abs(step) * -1
  • else:
  • step = abs(step)
  • for count in range(start, stop, step):
  • return_string += str(count) + ” “
  • return return_string.strip()
  • print(loop(11,2,3)) # Should be 11 8 5
  • print(loop(1,5,0)) # Should be 1 2 3 4
  • print(loop(-1,-2,0)) # Should be -1
  • print(loop(10,25,-2)) # Should be 10 12 14 16 18 20 22 24 
  • print(loop(1,1,1)) # Should be empty

Q7. The following code raises an error when executed. What’s the reason for the error?def decade_counter(): while year < 50: year += 10 return year

  • Failure to initialize variables

Q8. What is the value of x at the end of the following code?for x in range(1, 10, 3):    print(x)

  • 7

Q9. What is the value of y at the end of the following code?
for x in range(10):    for y in range(x):        print(y)

  • 8

Q10. How does this function need to be called to print yes, no, and maybe as possible options to vote for?

  • votes([‘yes’, ‘no’, ‘maybe’])

Module 4 – Graded Assessment Quiz Answers

Q1. The format_address function separates out parts of the address string into new strings: house_number and street_name, and returns: “house number X on street named Y”. The format of the input string is: numeric house number, followed by the street name which may contain numbers, but never by themselves, and could be several words long. For example, “123 Main Street”, “1001 1st Ave”, or “55 North Center Drive”. Fill in the gaps to complete this function.

  • def format_address(address_string):
  • hnum = []
  • sname = []
  • addr = address_string.split()
  • for a in addr:
  • if a.isnumeric():
  • hnum.append(a)
  • else:
  • sname.append(a)
  • return “house number {} on street named {}”.format(“”.join(hnum), ” “.join(sname))
  • print(format_address(“123 Main Street”))
  • # Should print: “house number 123 on street named Main Street”
  • print(format_address(“1001 1st Ave”))
  • # Should print: “house number 1001 on street named 1st Ave”
  • print(format_address(“55 North Center Drive”))
  • # Should print “house number 55 on street named North Center Drive”

Q2. The highlight_word function changes the given word in a sentence to its upper-case version. For example, highlight_word(“Have a nice day”, “nice”) returns “Have a NICE day”. Can you write this function in just one line?

  • def highlight_word(sentence, word):
  • return(sentence.replace(word,word.upper()))
  • print(highlight_word(“Have a nice day”, “nice”))
  • print(highlight_word(“Shhh, don’t be so loud!”, “loud”))
  • print(highlight_word(“Automating with Python is fun”, “fun”))

Q3. A professor with two assistants, Jamie and Drew, wants an attendance list of the students, in the order that they arrived in the classroom. Drew was the first one to note which students arrived, and then Jamie took over. After the class, they each entered their lists into the computer and emailed them to the professor, who needs to combine them into one, in the order of each student’s arrival. Jamie emailed a follow-up, saying that her list is in reverse order. Complete the steps to combine them into one list as follows: the contents of Drew’s list, followed by Jamie’s list in reverse order, to get an accurate list of the students as they arrived.

  • def combine_lists(list1, list2):
  • # Generate a new list containing the elements of list2
  • list_order = list2
  • list_reverse=list1
  • # Followed by the elements of list1 in reverse order
  • list_reverse.reverse()  #print (list_reverse)
  • list_combine =[]
  • for  word in list_order:
  • list_combine.append(word)
  • for word in list_reverse:
  • list_combine.append(word)
  • return  list_combine
  • Jamies_list = [“Alice”, “Cindy”, “Bobby”, “Jan”, “Peter”]
  • Drews_list = [“Mike”, “Carol”, “Greg”, “Marcia”]
  • print(combine_lists(Jamies_list, Drews_list))

Q4. Use a list comprehension to create a list of squared numbers (n*n). The function receives the variable’s start and end, and returns a list of squares of consecutive numbers between the start and end inclusively. For example, squares(2, 3) should return [4, 9].

  • def squares(start, end):
  • return [n*n for n in range(start,end+1)]
  • print(squares(2, 3)) # Should be [4, 9]
  • print(squares(1, 5)) # Should be [1, 4, 9, 16, 25]
  • print(squares(0, 10)) # Should be [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]

Q5. Complete the code to iterate through the keys and values of the car_prices dictionary, printing out some information about each one.

  • def car_listing(car_prices):
  • result = “”
  • for car, price in car_prices.items():
  • result += “{} costs {} dollars”.format(car, price) + “\n”
  • return result
  • print(car_listing({“Kia Soul”:19000, “Lamborghini Diablo”:55000, “Ford Fiesta”:13000, “Toyota Prius”:24000}))

Q6. Taylor and Rory are hosting a party. They sent out invitations, and each one collected responses into dictionaries, with names of their friends and how many guests each friend is bringing. Each dictionary is a partial list, but Rory’s list has more current information about the number of guests. Fill in the blanks to combine both dictionaries into one, with each friend listed only once, and the number of guests from Rory’s dictionary taking precedence, if a name is included in both dictionaries. Then print the resulting dictionary.

  • def combine_guests(guests1, guests2):
  •   # Combine both dictionaries into one, with each key listed 
  •   # only once, and the value from guests1 taking precedence
  •   new_guests = guests2.copy()
  •   new_guests.update(guests1)
  •   return new_guests
  • Rorys_guests = { “Adam”:2, “Brenda”:3, “David”:1, “Jose”:3, “Charlotte”:2, “Terry”:1, “Robert”:4}
  • Taylors_guests = { “David”:4, “Nancy”:1, “Robert”:2, “Adam”:1, “Samantha”:3, “Chris”:5}
  • print(combine_guests(Rorys_guests, Taylors_guests))

Q7. Use a dictionary to count the frequency of letters in the input string. Only letters should be counted, not blank spaces, numbers, or punctuation. Upper case should be considered the same as lower case. For example, count_letters(“This is a sentence.”) should return {‘t’: 2, ‘h’: 1, ‘i’: 2, ‘s’: 3, ‘a’: 1, ‘e’: 3, ‘n’: 2, ‘c’: 1}.

  • def count_letters(text):
  • result = {}
  •   # Go through each letter in the text
  •   for letter in text:
  • # Check if the letter needs to be counted or not
  • if letter.isupper():
  •  letter=letter.lower()
  • if letter.isalpha():
  • if letter not in result:
  • result[letter] = 0
  • result[letter] += 1
  • # Add or increment the value in the dictionary
  •   return result
  • print(count_letters(“AaBbCc”))
  • # Should be {‘a’: 2, ‘b’: 2, ‘c’: 2}
  • print(count_letters(“Math is fun! 2+2=4”))
  • # Should be {‘m’: 1, ‘a’: 1, ‘t’: 1, ‘h’: 1, ‘i’: 1, ‘s’: 1, ‘f’: 1, ‘u’: 1, ‘n’: 1}
  • print(count_letters(“This is a sentence.”))
  • # Should be {‘t’: 2, ‘h’: 1, ‘i’: 2, ‘s’: 3, ‘a’: 1, ‘e’: 3, ‘n’: 2, ‘c’: 1}

Q8. What do the following commands return when animal = “Hippopotamus”?

  • pop, t, us

Q9. What does the list “colors” contain after these commands are executed?colors = [“red”, “white”, “blue”]colors.insert(2, “yellow”)

  • [‘red’, ‘white’, ‘yellow’, ‘blue’]

Q10. What do the following commands return?

  • [‘router’, ‘localhost’, ‘google’]

Practice Quiz: Introduction to Programming

Q1. What’s a computer program?

  • A set of languages available in the computer
  • A process for getting duplicate values removed from a list
  • A list of instructions that the computer has to follow to reach a goal
  • A file that gets copied to all machines in the network

Q2. What’s the syntax of a language?

  • The rules of how to express things in that language
  • The subject of a sentence
  • The difference between one language and another
  • The meaning of the words

Q3. What’s the difference between a program and a script?

  • There’s not much difference, but scripts are usually simpler and shorter.
  • Scripts are only written in Python.
  • Scripts can only be used for simple tasks.
  • Programs are written by software engineers; scripts are written by system administrators.

Q4. Which of these scenarios are good candidates for automation? Select all that apply.

  • Generating a sales report, split by region and product type
  • Creating your own startup company
  • Helping a user who’s having network troubles
  • Copying a file to all computers in a company
  • Interviewing a candidate for a job
  • Sending personalized emails to subscribers of your website
  • Investigating the root cause of a machine failing to boot

Q5. What are semantics when applied to programming code and pseudocode?

  • The rules for how a programming instruction is written
  • The difference in number values in one instance of a script compared to another
  • The effect the programming instructions have
  • The end result of a programming instruction

Practice Quiz: Introduction to Python

Q1. Fill in the correct Python command to put “My first Python program” onto the screen.

print(“My first Python program”)

Output:

My first Python program

Q2. Python is an example of what type of programming language?

  • Platform-specific scripting language
  • General purpose scripting language
  • Client-side scripting language
  • Machine language

Q3. Convert this Bash command into Python:

# echo Have a nice day print(‘Have a nice day)

Output:

Have a nice day

Q4. Fill in the correct Python commands to put “This is fun!” onto the screen 5 times.

for i in range(5): print(“This is fun!”)

Output:

This is fun! This is fun! This is fun! This is fun! This is fun!

Q5. Select the Python code snippet that corresponds to the following Javascript snippet:

for (let i = 0; i < 10; i++) { console.log(i); }

for i in range(10): print(i)

Practice Quiz: Hello World

Q1. What are functions in Python?

  • Functions let us to use Python as a calculator.
  • Functions are pieces of code that perform a unit of work.
  • Functions are only used to print messages to the screen.
  • Functions are how we tell if our program is functioning or not.

Q2. What are keywords in Python?

  • Keywords are reserved words that are used to construct instructions.
  • Keywords are used to calculate mathematical operations.
  • Keywords are used to print messages like “Hello World!” to the screen.
  • Keywords are the words that we need to memorize to program in Python.

Q3. What does the print function do in Python?

  • The print function generates PDFs and sends it to the nearest printer.
  • The print function stores values provided by the user.
  • The print function outputs messages to the screen
  • The print function calculates mathematical operations.

Q4. Output a message that says “Programming in Python is fun!” to the screen.

print(“Programming in Python is fun!”)

Q5. Replace the _ placeholder and calculate the Golden ratio: $\frac{1+\sqrt{5}}{2}$

ratio = (1 + 5**.5) / 2 print(ratio)

Next Quiz Answers >>

Using Python to Interact with the Operating System

All Quiz Answers of Google IT Automation with Python Professional Certificate

Course 1: Crash Course on Python Coursera Quiz Answers

Course 2: Using Python to Interact with the Operating System

Course 3: Introduction to Git and GitHub

Course 4: Troubleshooting and Debugging Techniques

Course 5: Configuration Management and the Cloud

Course 6: Automating Real-World Tasks with Python

Share your love

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Your email address will not be published. Required fields are marked *