IT 2108 - Object Oriented Programming 1 - Python: You Can Upload The File
IT 2108 - Object Oriented Programming 1 - Python: You Can Upload The File
IT 2108 - Object Oriented Programming 1 - Python: You Can Upload The File
Submission: You can submit the assessment tasks to our Google Classroom, I’ll be posting later where
you can upload the file.
Filename: BSIT-2D_Surname. I will not accept incorrect filenames so double check before you submit
the assessment tasks.
Module No. 1
Activity #1.
1.It is a cross platform programming language,which means that it can be run on multiple platform like
window and etc.It is also an object oriented scripting language and designed to he highly readable.
Python is processed at runtime by interpreter.
2. Anaconda is a package manager, an environment manager and Python distribution that contains a
collection of many open source package.
B. Locate your download and double click it. When the screen below appears, Click next.
D. Click on next.
G. Click on next.
I. Click on finish.
3.
print("Benjie B. Jayona\n")
print("Laguna University\n")
print("Santa Cruz,Laguna\n\n")
Module 2
Activity 1
1. Numbers
Python allows programmer to use several different types of numbers. Integers, floating point numbers
and complex number fall under number.
2. Strings
It is used in Python to record text information such as names. String in python are actually a
sequence,which basically means python keeps track of every elements in the string as in sequence.
3. List
List can be thought of the most general version of a sequence in python. Unlike strings, they are
mutable- meaning the elements inside a list can be change.
4. Tuples
It is similar to list,however, unlikr list they are immutable meaning they cannot be change. You would
use tuples to present things that shouldnt be changes, such as day of the week or dates on a calendar.
5. Dictionaries
It is the mapping of sequence in python. Mapping are a collection of objects that stored by a key.
6. Boolean
Python cames with boolean ( with predefined True or false display that are basically just the integers 1
and 0). It is also has a placeholder object called None.
Activity 2
1.
x=1.25+(5**2*8/2)-1
print(x)
2.
4*(6+5)=44
a=4*(6+5)
print(a)
4*6+5=29
a=4*6+5
print(a)
4+6*5
a=4+6*5
print(a)
4. By **(0.5)
5**(0.5)
5. By **
5**2
6.
a='Hello'
print(a[1])
7.
a='Hello'
print(a[::-1])
8.
s='Hello'
print(s[4])
s='Hello'
print(s[-1])
9.
A.
mylist=[0,0,0]
B.
mylist=[]
10.
list3=[1,2,[3,4,'hello']]
list3[2].pop(2)
print(list3)
list3[2].append('goodbye')
print(list3)
11.
list4={5,3,4,6,1}
print(list4.reverse())
12.
A.
d={'simple_key':'Hello'}
print(d['simple_key'][0:5])
B.
d={'k1':{'k2':'hello'}}
print(d['k1']['k2'][0:5])
C.
d={'k1':[{'nested_key':['this is deep',['hello']]}]}
print(d['k1'][0]['nested_key'][1]
D.
d={'k1':[1,2,{'k2':['this is tricky',['tough':[1,2,['hello']]}]}]}
print(d['k1'][2]['k2'][1]['tough'][2])
13. No, because dictionary can have both string and integer so that it is hard to be sort. Also it is
mutable. Also, dictionary are mapping and not sequence.
14. Tuples is immutable and cannot be changed while list is mutable and can be change.
15.
For example
s=(1,2,3)
print(s[0])
Output: 1
17.
list5=[1,2,2,33,4,4,11,22,3,3,2]
print(set(list5))
18.
A. True
B. Not true
C. True
D. Not true
19.False
Module 3
1.
for a in b.split():
if a.startswith("s")
print(a)
2.
start = 0
end = 10
if num % 2 == 0:
def even_words(str):
value = str.split()
if len(word)%2==0:
print(word)
str = "Print every word in this sentence that has an even number of letters"
even_words(str)
4.
first = 1
second = 100
print("Fizzbuzz")
elif num%3==0:
print("Fizz")
elif num%5==0:
print("Buzz")
else:
print(num)
Module 4
1.Write a function that computes the volume of a sphere given its radius.
def vol(radius):
pi=3.14
vol=(4.0/3)*pi*(radius**3)
return vol
vol(3)
2.Write a function that checks whether a number is in a given range (Inclusive of high and low)
def ran_check(number,low,high):
for i in range(low,high+1):
if number==i:
break
else :
ran_check(3,5,10)
def ran_bool(number,low,high):
for i in range(low,high+1):
if number==i:
print True
break
else :
print False
ran_bool(3,1,10)
3.Write a Python function that accepts a string and calculate the number of upper case letters and lower
case letters.**
Sample String : 'Hello Mr. Rogers, how are you this fine Tuesday?'
Expected Output :
If you feel ambitious, explore the Collections module to solve this problem!
def up_low(s):
ucount=0
lcount=0
for letter in s:
if str.isupper(let):
ucount+=1
elif str.islower(let):
lcount+=1
4.Write a Python function that takes a list and returns a new list with unique elements of the first list.**
def unique_list(l):
x=set(l)
print list(x)
unique_list([1,1,1,1,2,2,3,3,3,3,4,5])
product=1
product=product*num
return product
multiply([1,2,3,-4])
6.Write a Python function that checks whether a passed string is palindrome or not.**
Note: A palindrome is word, phrase, or sequence that reads the same backward as forward, e.g.,
madam or nurses run.
def palindrome(s):
reverse_s=s[::-1]
if s==reverse_s:
print('string is palindrome')
else:
print('not a palidrome')
palindrome('tapat')
____
Hard
Note : Pangrams are words or sentences containing every letter of the alphabet at least once.
For example : "The quick brown fox jumps over the lazy dog"
import string
s=str.lower(str1)
string=str.replace(s,' ','')
if str.find(string,alpha)==-1:
return False
break
else:
return True
Laboratory activity
Write a Python function to check whether a string is pangram or not.
Note : Pangrams are words or sentences containing every letter of the alphabet at least once.
For example : "The quick brown fox jumps over the lazy dog"
import string
s=str.lower(str1)
string=str.replace(s,' ','')
if str.find(string,alpha)==-1:
return False
break
else:
return True