Python for everybody Week 4 Quiz Answer
Hello Friends in this article i am gone to share Coursera Course: Python Data Structures Week 4 Quiz Answers with you..
Python Data Structures
Go to this Course: Python Data Structures
Python Data Structures Week 4 Quiz Answers
Which Python keyword indicates the start of a function definition?
In Python, how do you indicate the end of the block of code that makes up the function?
- You put a # character at the end of the last line of the function
- You de-indent a line of code to the same indent level as the def keyword
- You add a line that has at least 10 dashes
- You put the colon character (:) in the first column of a line
In Python what is the raw_input() feature best described as?
- A conditional statement
- A data structure that can hold multiple values using strings as keys
- A built-in function
- A reserved word
What does the following code print out?
In the following Python code, which of the following is an “argument” to a function?
- x = ‘banana’
- y = max(x)
- print y
- print x
What will the following Python code print out?
def func(x) :
Which line of the following Python program is useless?
- print ‘Hello’
- def stuff():
- print ‘World’
What will the following Python program print out?</span >
if lang == ‘es’:
elif lang == ‘fr’:
- Bonjour Michael
- Hello Michael
- def Michael
What does the following Python code print out? (Note that this is a bit of a trick question and the code has what many would consider to be a flaw/bug – so read carefully).
def addtwo(a, b):
added = a + b
x = addtwo(2, 7)
What is the most important benefit of writing your own functions?
- Following the rule that no function can have more than 10 statements in it
- Avoiding writing the same non-trivial code more than once in your program
- To avoid having more than 10 lines of sequential code without an indent or de-indent
- Following the rule that whenever a program is more than 10 lines you must use a function
Week 4 Assignment
4.6 Write a program to prompt the user for hours and rate per hour using raw_input to compute gross pay. Award time-and-a-half for the hourly rate for all hours worked above 40 hours. Put the logic to do the computation of time-and-a-half in a function called computepay() and use the function to do the computation. The function should return a value. Use 45 hours and a rate of 10.50 per hour to test the program (the pay should be 498.75). You should use raw_input to read a string and float() to convert the string to a number. Do not worry about error checking the user input unless you want to – you can assume the user types numbers properly.</b >
if h > 40:
return (40*r)+(h-40)*(r*1.5)</i >
return h*r</i >
hrs = raw_input(“Enter Hours:”)
rate = raw_input(“Enter Rate:”)
hrs = float(hrs)
rate = float(rate)
p = computepay(hrs, rate)