need to finish the code for the following 6 functions all of

need to finish the code for the following 6 functions all of which are commented out. Language required is Python.

# Demo function and test code

def three():

   # Input: none

   # Output: 3

   return 2

   

if (three() == 3):

   print(\"three(): PASS\")

else:

   print(\"three(): FIX\")

print()

\'\'\'

# Function #1 and test code    

def sum_1to(n):

   # input: a number >= 1

   # output: sum of numbers from 1 to n

if (sum_1to(3) == 6):

   print(\"sum_1to(3): PASS\")

else:

   print(\"sum_1to(3): FIX\")

   

if (sum_1to(100) == 5050):

   print(\"sum_1to(100): PASS\")

else:

   print(\"sum_1to(100): FIX\")

print()

   

   

# Function #2 and test code

def log_base2(n):

   # Calculates log base 2 of n.

   # Log base 2 of n is the number of times you can cut n in half

   # and get a number that is >= 1. Log base 2 of 8 is 3 because you

   # can cut 8 in half 3 times: (8 -> 4 -> 2 -> 1).

if (log_base2(8) == 3):

   print(\"log_base2(8): PASS\")

else:

   print(\"log_base2(8): FIX\")

   

if (log_base2(1024) == 10):

   print(\"log_base2(1024): PASS\")

else:

   print(\"log_base2(1024): FIX\")

print()    

# Function #3 and test code

def is_valid_password(password):

   # Returns True if password has 6 or more characters and

   # contains at least one digit. Otherwise returns False.

   # Hint: isdigit() is a string method.

if (is_valid_password(\'nope5\') == False):

   print(\"is_valid_password(\'nope5\'): PASS\")

else:

   print(\"is_valid_password(\'nope5\'): FIX\")

if (is_valid_password(\'4gotten\') == True):

   print(\"is_valid_password(\'4gotten\'): PASS\")

else:

   print(\"is_valid_password(\'4gotten\'): FIX\")

   

if (is_valid_password(\'123456\') == True):

   print(\"is_valid_password(\'123456\'): PASS\")

else:

   print(\"is_valid_password(\'123456\'): FIX\")

print()

# Function #4 and test code

def capital(search_state):

   # Returns the capital city of search_state if it\'s in

   # the database. Otherwise, returns \"Not Found.\"

   data = [[\"PA\", \"Harrisburgh\"], [\"NJ\", \"Trenton\"], [\"NY\", \"Albany\"]]

   

if (capital(\'NY\') == \'Albany\'):

   print(\"capital(\'NY\'): PASS\")

else:

   print(\"capital(\'NY\'): FIX\")    

   

if (capital(\'DE\') == \'Not Found\'):

   print(\"capital(\'DE\'): PASS\")

else:

   print(\"capital(\'DE\'): FIX\")

if (capital(\'PA\') == \'Harrisburgh\'):

   print(\"capital(\'PA\'): PASS\")

else:

   print(\"capital(\'PA\'): FIX\")    

print()

# Function #5 and test code

def website_type(url):

   # Input: A URL (web address). Assume it has at least one \'.\'

   # Output: \'commercial\', \'government\', \'education\', or

   # \'other\' based on the postfix (.com, .gov, .edu or other).

   

if (website_type(\'https:/www.healthcare.gov\') == \'government\'):

   print(\"website_type(\'https:/www.healthcare.gov\'): PASS\")

else:

   print(\"website_type(\'https:/www.healthcare.gov\'): FIX\")    

if (website_type(\'http://www.temple.edu\') == \'education\'):

   print(\"website_type(\'http://www.temple.edu\'): PASS\")

else:

   print(\"website_type(\'https:/www.healthcare.gov\'): FIX\")

   

if (website_type(\'startit.net\') == \'other\'):

   print(\"website_type(\'startit.net\'): PASS\")

else:

   print(\"website_type(\'startit.net\'): FIX\")

print()

# Function #6 and test code

def search(text, search_string):

   # Searches text for search_string. Returns index of first

   # occurrence or -1 if not found.

   # Hint: Use a string method for a 1-line solution.

   #       Then try writing a solution without string methods.

if (search(\'i see you\', \'see\') == 2):

   print(\"search(\'i see you\', \'see\'): PASS\")

else:

   print(\"search(\'i see you\', \'see\'): FIX\")

   

if (search(\'where is waldo?\', \'hmm\') == -1):

   print(\"search(\'where is waldo?\', \'hmm\'): PASS\")

else:

   print(\"search(\'where is waldo?\', \'hmm\'): FIX\")

   

if (search(\'wonder\', \'won\') == 0):

   print(\"search(\'wonder\', \'won\'): PASS\")

else:

   print(\"search(\'wonder\', \'won\'): FIX\")

\'\'\'    

Solution

When calculations are carried out electronically they will usually be in binary or twos complement notation, but the result will very probably need to be displayed in decimal form. A binary number with its bits representing values of 1, 2, 4, 8, 16 etc. presents problems. It

need to finish the code for the following 6 functions all of which are commented out. Language required is Python. # Demo function and test code def three(): #
need to finish the code for the following 6 functions all of which are commented out. Language required is Python. # Demo function and test code def three(): #
need to finish the code for the following 6 functions all of which are commented out. Language required is Python. # Demo function and test code def three(): #
need to finish the code for the following 6 functions all of which are commented out. Language required is Python. # Demo function and test code def three(): #

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site