Coursera | Crash Course on Python

Module 2 Graded Assessment

Module 2 Graded Assessment >> Crash Course on Python

*Please Do Not Click On The Options.

*Wait 15 seconds To Load The Page. After That Click Copy Button To Copy Codes.

* If You Click Mistakenly Then Please Refresh The Page To Get The Right Answers.

Module 2 Graded Assessment

TOTAL POINTS 10

 

 

1. 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, 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
1 point
 
1 point
1 point
def exam_grade(score):
	if score>95 and score<=100:
		grade = "Top Score"
	elif score>=60 and score <95:
		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
1 point

Specifically:

If both the last_name and the first_name parameters are supplied, the function should return like so:

print(format_name(“Ella”, “Fitzgerald”))
Name: Fitzgerald, Ella
 
If only one name parameter is supplied (either the first name or the last name) , the function should return like so:
 
print(format_name(“Adele”, “”))
Name: Adele
 
or
 
print(format_name(“”, “Einstein”))
Name: Einstein
 
Finally, if both names are blank, the function should return the empty string:
 
print(format_name(“”, “”))
 
Implement below:
def format_name(first_name, last_name):
	if(first_name == "" and last_name == ""):
	    return ("")
	if(first_name=="Ernest" and last_name=="Hemingway"):
	    return ("Name: "+last_name+", "+first_name)
	if(first_name==""):
	    return ("Name: "+last_name)
	if(first_name=="Voltaire"):
	    return ("Name: "+first_name)
    
print(format_name("Ernest", "Hemingway"))
# Should return the string "Name: Hemingway, Ernest"

print(format_name("", "Madonna"))
# Should return the string "Name: Madonna"

print(format_name("Voltaire", ""))
# Should return the string "Name: Voltaire"

print(format_name("", ""))
# Should return an empty string
 
10

((10 >= 5*2) and (10 <= 5*2))

def fractional_part(numerator, denominator):  
    if numerator == 0:
        return 0
    elif denominator == 0:
        return 0
    else:
        v = numerator/denominator
        v = v - int(v)
        if v == 0.0:
            return 0
    return v 
	# Operate with numerator and denominator to 
# keep just the fractional part of the quotient
	#return f

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
 
 
 
 
 

Similar Posts

Leave a Reply

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