Name Sisay Amare Nigussie REGE NO 18BCM0149 Winter Semester 2019-2020 Problem Solving and Programming (Assessment 3 and Assessment 5)
Name Sisay Amare Nigussie REGE NO 18BCM0149 Winter Semester 2019-2020 Problem Solving and Programming (Assessment 3 and Assessment 5)
REGE NO 18BCM0149
Winter Semester 2019-2020
Problem Solving and Programming (Assessment 3 and
Assessment 5)
Assessment 3:
1. Create a list with 20 integers, iterate it and display numbers which
are
divisible by 6 and if you find number greater than 150 stop the loop
iteration (5)
solution:
Program/Source Code
list1 = [12, 15,22,24, 32, 36,42, 49,55, 75, 118,122, 132, 144,148,150,
160,170,180, 200]
for item in list1:
if (item > 150):
break
if(item % 6 == 0):
print(item)
out put:
12
24
36
42
132
144
150
2. Create a function named as Employeeinfo() in such a way that it
should
accept employee name, and it’s salary and display both, and if the
salary is
missing in function, the output should show salary as 8000 (5)
class Employee:
name=""
salary=0
def setData(self,name,salary):
self.__name = name
self.__salary = salary
def showData(self):
print("Name\t:", self.__name)
print("Salary\t:", self.__salary)
def main():
emp=Employee()
if(salary=55000):
emp.setData('pankaj',55000)
else:
emp.setData('pankaj',8000)
emp.showData()
if __name__=="__main__":
main()
Assessment 5:
1. Given 2 strings, string1 and string2: Return a new string made of
the first,
middle and last char each input string. (5)
solution:
Program/Source Code
s1 = "Ethiopia"
s2 = "India"
mixString(s1, s2)
out put
Mix String is EIodaa
2. Create a string with upper case, lower case, digits and special
symbols.
Develop a program to count and display the no.of . lower case
alphabets,
no.of.upper case alphabets, no.of.digits, and no.of.special symbols
(5)
Solution:-
Program/Source Code
def count_chars(str):
upper_ctr, lower_ctr, number_ctr, special_ctr = 0, 0, 0, 0
for i in range(len(str)):
if str[i] >= 'A' and str[i] <= 'Z': upper_ctr += 1
elif str[i] >= 'a' and str[i] <= 'z': lower_ctr += 1
elif str[i] >= '0' and str[i] <= '9': number_ctr += 1
else: special_ctr += 1
return upper_ctr, lower_ctr, number_ctr, special_ctr
str = "@S4Ethiopia1.Com"
print("Original Substrings:",str)
u, l, n, s = count_chars(str)
print('\nUpper case characters: ',u)
print('Lower case characters: ',l)
print('Number case: ',n)
print('Special case characters: ',s)
Output: