0% found this document useful (0 votes)
25 views

Name Sisay Amare Nigussie REGE NO 18BCM0149 Winter Semester 2019-2020 Problem Solving and Programming (Assessment 3 and Assessment 5)

The document contains information about two programming assignments for a problem solving and programming course. The first assignment asks to create a list of integers, iterate through it, and print numbers divisible by 6 until reaching a number greater than 150. The second asks to create an employee class that accepts and displays a name and salary, defaulting to 8000 if no salary is provided. The second assignment asks to take the first, middle, and last characters of two input strings and combine them. It provides a sample input and output. The third asks to count the numbers of uppercase letters, lowercase letters, digits, and special symbols in a provided string and display the results. It provides the input string and sample output.

Uploaded by

Sisay Amare
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Name Sisay Amare Nigussie REGE NO 18BCM0149 Winter Semester 2019-2020 Problem Solving and Programming (Assessment 3 and Assessment 5)

The document contains information about two programming assignments for a problem solving and programming course. The first assignment asks to create a list of integers, iterate through it, and print numbers divisible by 6 until reaching a number greater than 150. The second asks to create an employee class that accepts and displays a name and salary, defaulting to 8000 if no salary is provided. The second assignment asks to take the first, middle, and last characters of two input strings and combine them. It provides a sample input and output. The third asks to count the numbers of uppercase letters, lowercase letters, digits, and special symbols in a provided string and display the results. It provides the input string and sample output.

Uploaded by

Sisay Amare
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

NAME SISAY AMARE NIGUSSIE

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

def mixString(s1, s2):


resultString = s1[:1] + s2[:1] + s1[int(len(s1) /2):int(len(s1) /2)+1]
+s2[int(len(s2) /2):int(len(s2) /2)+1] +s1[len(s1)-1] + s2[len(s2)-1]
print("Mix String is ", resultString)

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:

Original Substrings: @S4Ethiopia1.Com

Upper case characters: 3


Lower case characters: 9
Number case: 2
Special case characters: 2

You might also like