SYAMAPRASAD INSTITUTE OF TECHNOLOGY & MANAGEMENT
Continuous Assessment - CA2
Subject name - Python
Subject code - BCA 301
Student name - Sulagna Dutta
University roll no. - 15342723045
University Registration Number - 23151010045 of
2023-24
Semester - 3rd Year - 2nd
Session - 2024-25
Table of Content
1. Write a python program to accept a year and find out
whether it is a leap year or not.
2. Write a python program to find the greatest between three
numbers accepted from user.
3. Compare and contrast between List and Dictionary
Write a python program to accept a year and find
out whether it is a leap year or not
Algorithm to Check if a Year is a Leap Year :
Step 1: Input the Year
● Read the year from the user or input source and store it in a variable called
Year.
Step 2: Check if the Year is Divisible by 400
● If True: The year is a leap year.
○ Print "Yes! This Year is a Leap Year".
○ End the process.
● If False: Proceed to the next step.
Step 3: Check if the Year is Divisible by 100
● If True: The year is not a leap year.
○ Print "This Year is not a leap Year".
○ End the process.
● If False: Proceed to the next step.
Step 4: Check if the Year is Divisible by 4
● If True: The year is a leap year.
○ Print "Yes! This Year is a Leap Year".
● If False: The year is not a leap year.
○ Print "This Year is not a leap Year".
Program to Check if a Year is Leap Year :
def CheckLeap(Year):
# Checking if the given year is leap year
if((Year % 400 == 0) or (Year % 100 != 0) and (Year % 4 == 0)):
print("Yes! This Year is a leap Year");
# Else it is not a leap year
else:
print ("This Year is not a leap Year")
# Taking an input year from user
Year = int(input("Enter the number here: "))
# Printing result
CheckLeap(Year)
Output :
Enter the number here : 2024
Yes! This year is a leap Year
Write a python program to find the greatest between three
numbers accepted from user
Algorithm to find the greatest between two numbers :
1. Step 1: Start.
2. Step 2: Prompt the user to input the first number (num1).
3. Step 3: Prompt the user to input the second number (num2).
4. Step 4: Prompt the user to input the third number (num3).
5. Step 5: Check if num1 is greater than or equal to both num2 and num3.
○ If true, set largest to num1.
6. Step 6: Else, check if num2 is greater than or equal to both num1 and
num3.
○ If true, set largest to num2.
7. Step 7: Else, set largest to num3.
8. Step 8: Display largest as the largest number.
9. Step 9: End.
Program to find the greatest between two numbers :
# Taking an input year from user
num1 = int(input("Enter the first number :"))
num2 = int(input("Enter the second number :"))
num3 = int(input("Enter the third number :"))
#Checking for the largest number
if (num1 >= num2) and (num1 >= num3):
largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3
#Printing the result
print("The largest number is", largest)
Output :
Enter the first number :3
Enter the second number :6
Enter the third number :5
The largest number is 6
Introduction to List & Dictionary in Python
Lists in Python
A list is a data structure in Python that is a mutable, or changeable,
ordered sequence of elements. Each element or value that is inside of a list is called an
item. Just as strings are defined as characters between quotes, lists are defined by
having values between square brackets [ ] .
Example :
# Creating a 1D List
List = ["Lana", "Del", "Rey"]
# List of Strings
print("List containing multiple values: ", List)
# Accessing particular elements
print(List[0])
print(List[0][1])
print(List[1])
# Creating a 2D List
List = [['Lana', 'Del'], ['Rey']]
print("\nMulti-Dimensional List: ", List)
# Accessing particular elements
print(List[0]) print(List[0][1])
print(List[1])
Output :
List containing multiple values: ['Lana', 'Del', 'Rey'] Lana
a Del
Multi-Dimensional List: [['Lana', 'Del'], ['Rey']]
['Lana', 'Del'] Del ['Rey']
Dictionary in Python :
In Python, dictionaries are mutable data structures that allow you to store
key-value pairs. Dictionary can be created using the dict() constructor or curly braces' {}'.
Once you have created a dictionary, you can add, remove, or update elements using the
methods dict. update(), dict.
Example :
# Creating a Dictionary with Integer Keys
Dict = {1: 'Apple', 2: 'Banana', 3: 'Grape'}
print("Dictionary with the use of Integer Keys: ", Dict)
# Accessing particular elements
print(Dict[1])
print(Dict[2])
# Creating a Dictionary with Mixed keys
Dict = {'Name': 'Apple', 1: [1, 2, 3, 4]}
print("\nDictionary with the use of Mixed Keys: ", Dict)
# Accessing particular elements
print(Dict['Name'])
print(Dict[1])
Output :
Dictionary with the use of Integer Keys: {1: 'Apple', 2: 'Banana', 3: 'Grape'} Apple Banana
Dictionary with the use of Mixed Keys: {'Name': 'Apple', 1: [1, 2, 3, 4]} Apple [1, 2, 3, 4]
Compare and contrast between List and Dictionary
List Dictionary
The list is a collection of index value
The dictionary is a hashed structure of
pairs like ArrayList in Java and
the key and value pairs.
Vectors in C++.
The dictionary is created by placing
The list is created by placing elements elements in { } as “key”:”value”, each
in [ ] separated by commas “, “ key-value pair is separated by commas
“, “
The indices of the list are integers The keys of the dictionary can be of any
starting from 0. immutable data type.
The elements are accessed via indices. The elements are accessed via key.
They are unordered in python 3.6 and
The order of the elements entered is
below and are ordered in python 3.7 and
maintained.
above.
Dictionaries cannot contain duplicate
Lists can duplicate values since each
keys but can contain duplicate values
values have unique index.
since each value has unique key.
Average time taken to search a value in Average time taken to search a key in
list takes O[n]. dictionary takes O[1].
Average time to delete a certain value Average time to delete a certain key
from a list takes O[n]. from a dictionary takes O[1].
Bibliography
Books:
Reema Thareja. PYTHON PROGRAMMING.
Oxford University Press, 2017.
Website:
GeekForGeeks :
https://www.geeksforgeeks.org/di erence-betwe en-
list-and-dictionary-in-python/
Thank You / Acknowledgements
I would like to extend my heartfelt thanks to the following
individuals for their invaluable guidance and support during the
writing of this report:
Prof. Amit Kumar Das, for their expert knowledge,
insightful guidance, and continuous encouragement
throughout the report writing process.
Prof. Suchandra Roy, for their practical assistance, feedback,
and support, which were instrumental in shaping the
content of this report.
Your contributions have been key to the successful completion of
this work, and I am truly grateful for your help.