UNIVERSITY OF ENGINEERING AND TECHNOLOGY, LAHORE
(NAROWAL CAMPUS)
(UET)
BSc. BIOMEDICAL ENGINEERING
(BME)
Introduction to Computer Programming for Data Science
Course Title:
Introduction to Computer Programming for Data Science
Course Code:
CS-103
Submitted By:
Muhammad Amir Sohail
2021-BME-104
Department of Biomedical Engineering
Submitted To:
Ma’am Fatima Shehzadi
Assignment No:
#1
Introduction to Computer
Programming for Data Science
CS-103
Assignment #01 (CLO Mapping -> CLO 1)
Objective:
Theoretical experience over the ground knowledge.
Practical experience over the control structures.
In each of the Programming problems, you are required to
draw the flow chart
Write it as Python code.
Programming Problem# 1:
Design a solution of problem to check leap year.
Leap years are perfectly divisible by 4.00. For example: 2012, 2004, 1968 etc. are leap year but, 1971, 2006
etc. are not leap year. Similarly, 1200, 1600, 2000, 2400 are leap years but, 1700, 1800, 1900 etc. are not.
In this program, user is asked to enter a year and this program checks whether the year entered by user is
leap year or not.
(you are encouraged to use Nested if else)
Code for Problem1:
year = int(input("Enter the value of a year: "))
if year % 400 == 0:
print("This year",year, "is a leap year")
elif year % 100 == 0 and year % 400 != 0:
print("This year",year, "is not a leap year")
elif year % 4 == 0:
print("This year",year, "is a leap year")
else:
print("This year",year, "is not a leap year")
Implementation of Code in Jupyter:
Figure 1 Code for problem program 1
Flow chart:
start
Enter the value
ssss of
year
Yes Is this divided
by 400?
No
Is this divided Yes
by 100?
Yes Is this divided No
This year is a leap
by 4? This is not leap year
year
End
Programming Problem# 2:
Design a program which takes CGP (cumulative grade point) of a person and allocates room in hostel after
first year. (We have 8 hostels for consideration after first year)
Person having CGP above 2 will only be considered for single room in Hostel (1…7).
Person having CGP lower than 2 would be allotted seat in double room (Hostel 8)
CGP lower than 2.5 would be considered for having single room on 2nd floor.
Person having CGP above 2.5, 3 would be allotted as 1st floor and ground floor room
respectively.
(Use the sentinel controlled repetition to allocate the hostel seats)
Code for Problem2:
while True:
cgp = float(input("Enter your CGP: "))
if cgp > 3:
print("You have been allotted a single room on the ground floor.")
elif cgp > 2.5:
print("You have been allotted a single room on the first floor.")
elif cgp > 2:
print("you have been allotted a single room in hostel 1 to 7 randomly")
elif cgp > 0:
print("You have been allotted a double room in Hostel 8.")
else:
print("Invalid CGP. Please enter a valid CGP.")
choice = input("Do you want to continue? (Y/N): ")
if choice.lower() != "y":
break
Implementation of Code in Jupyter:
Figure 2 Code and implementation of problem program 2
Flow chart:
Start
Enter your CGP
single room on
Yes
cgp > 3
the ground
floor
No
cgp > single room on
2.5>3 Yes the first floor
No
Yes
single room in cgp >
hostel 1 to 7 2>2.5
randomly
No
Yes
cgp > 0>2 double room in
Hostel 8
End
Programming Problem# 3:
Design a Python program which takes size of diamond and display hollow diamond using nested while loop
and asterisk character.
Output should be look like below
User can enter its desired size of diamond either even or odd
For Example
If user enters size of 3
3 lines of will be formed above middle and 3 lines will be formed below middle
line.
Code for Problem3:
size = int(input("Enter the size of the diamond: "))
# Upper half of the hollow diamond
i=1
while i <= size:
print(" " * (size - i) + "*" + " " * (2 * (i - 1) - 1) + "*"*(i!=1))
i += 1
# Lower half of the hollow diamond
i = size - 1
while i >= 1:
print(" " * (size - i) + "*" + " " * (2 * (i - 1) - 1) + "*"*(i!=1))
i -= 1
Implementation of Code in Jupyter:
Figure 3 Code and implementation of problem program 2
Flow chart:
Start
Size of diamond
Initialize Row
Row
size
Yes
Print space & star for upper part
& increment
Yes
Row
size
No
Print space & stars for lower part
End
Programming Problem# 4:
A palindrome is a number or a text phrase that reads the same backwards as forwards. For example, each
of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write a program that
reads in a five-digit integer and determines whether it is a palindrome or not using loops.
Code for Problem3:
number = input("Enter a five-digit integer: ")
# Check if the number is a palindrome
is_palindrome = True
for i in range(len(number) // 2):
if number[i] != number[-(i + 1)]:
is_palindrome = False
break
# Display the result
if is_palindrome:
print("The number is a palindrome.")
else:
print("The number is not a palindrome.")
Implementation of Code in Jupyter:
Figure 4 Figure 5 Code and implementation of problem program 4
Flow chart:
Start
Enter 5 digit
number
Check the
Yes No
number is a
palindrome or
not
Print the number is a Print the number is not a
palindrome palindrome
End