CS158-1L: Artificial Intelligence Laboratory
Machine Problem #1: Getting Started with Python
Name: Score:
Section: Date:
OBJECTIVES
● To familiarize the students with the python interface.
● To enable the students to use some basic operations.
Instructions:
1. Save your file as Surname_Firstname_MP1. Ex. Santos_Jared_MP1
2. You will submit a zip file and containing the following and send it to BB .
a. PDF file of Machine Problem 1 provided with the screenshot of your answers.
b. Python script with .py extension.
3. Your program must have comments for each section.
Header Comments at the beginning of your code:
#This program shows how good a Python program is
#Written by:Raymond Sedilla
#Date: August 27,2021
#Time: 2:20pm
#Program: BSIE
#Course: CS158-1L
#Section: B10
#School: Mapua University
Note: Your output should be displayed rounded to two decimal places.
Rubrics for Problem A and B
1. Correct output 35
2. Complete submission of files 10
3. Readability and comments 5
PROBLEM
Prepared by: Raymond Sedilla, Mapua University
CS158-1L: Artificial Intelligence Laboratory
Machine Problem #1: Getting Started with Python
a. Write a function script in python that will return the following:
def formatname(first_name, last_name):
________________?
________________?
return ?
print(format_name("John", "Katigbak"))
# Should return the string "Name: Katigbak, John"
print(format_name("", "Domingo"))
# Should return the string "Name: Domingo"
print(format_name("Bon Ryan", ""))
# Should return the string "Name: Bon Ryan"
print(format_name("", ""))
# Should return an empty string
b. The function “fractional” divides the numerator by the denominator and returns just the
fractional part (a number between 0 and 1).
def fractionalpart(numerator, denominator):
_______________?
# keep just the fractional part of the quotient
return ?
print(fractionalpart(5, 5)) # Should be 0
print(fractionalpart(5, 4)) # Should be 0.25
print(fractionalpart(5, 3)) # Should be 0.66...
print(fractionalpart(5, 2)) # Should be 0.5
print(fractionalpart(5, 0)) # Should be 0
print(fractionalpart(0, 5)) # Should be 0
Screenshot of your python script:
Prepared by: Raymond Sedilla, Mapua University
CS158-1L: Artificial Intelligence Laboratory
Machine Problem #1: Getting Started with Python
Screenshot of your python script output:
Prepared by: Raymond Sedilla, Mapua University
CS158-1L: Artificial Intelligence Laboratory
Machine Problem #1: Getting Started with Python
Prepared by: Raymond Sedilla, Mapua University