



















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




















An Assignment On Python Bachelor of Computer Application From Pt. Ravishankar Shukla University, Raipur (C.G.) Year: 2025-
Guided By: Submitted By:
Mrs. Preeti Mishra XYZ
Assistant Professor BCA 4th Sem
Department of Computer
Submitted to Department of Computer Vipra Kala, Vanijya Avam Sharirik Shiksha Mahavidyalaya, Doomar Talab, Raipur (C.G.), India
S.No Topic Page. No Signature
a Introduction to Python 1
b Installation Process of python 2
c Python Functions and their types 3
d Statements in Python 4
e List, Tuple and Dictionary 4-
f Built in string methods 5-
g Loop control structures 6-
h Python identifiers, Reserved keywords 7
i Comments in python, Line and indentation
S.No Programme Name Page. No Signature
1 Write a python program that asks for their name and age,
9 Write a Python Program that takes a lowercase string from the user and converts it into uppercase.
10 Write a function that takes a string input and checks if it is a palindrome or not.
11 Write a python program that defines a function to calculate the sum of two
12 Create a tuple representing the days of the week and update the last element with “Sunday”. Print the updated tuple.
13 Write a Python program that concatenated tuple.
14 WAP to create a list of numbers and sort the list in ascending order.
15 Write a list function to convert a string into a list, as in list (-abc) gives [a,b,c].
Python is a versaƟle, high-level programming language known for its simple syntax that closely resembles the English language. It is “interpreted”, meaning code is executed line- by-line as soon as it is wriƩen, allowing for every quick prototyping and development.
Readability: Designed with an emphasis on code readability, it uses significant indentaƟon rather than braces to define code blocks. BaƩeries-Included: Python comes with an extensive standard library of ready-to-use tools for various task. Cross-Plaƞorm: It runs seamlessly on Windows, Mac, Linux, and even Raspberry Pi. Dynamic Typing: You don’t need to declare variables type explicitly; Python detects them automaƟcally at runƟme.
Web Development: Power backs-end systems using frameworks like Django and Flask. AutomaƟon: Ideal for wriƟng simple scripts to automate repeƟƟve tasks like file handling or web scraping. Data Science and AI: Used for data analysis and machine learning with libraries like pandas and TensorFlow.
print(“Hello, World!”)
In Python, a funcƟon is a reusable block of code that perform a specific task when called. They help in organizing code into modular secƟons, reducing repeƟƟon and making programs easier to manage.
Built-in FuncƟons: Predefined funcƟons that are always available in python. You can use them directly without any import, such as print(), len(), abs(), and type(). User-defined funcƟons: FuncƟons created by programmers using the def keyword to perform custom tasks specific to their applicaƟon. Anonymous (Lambda) FuncƟon: Small, unnamed funcƟons defined with the lambda keyword. They are typically used for short, one-Ɵme operaƟons. Recursive FuncƟons: FuncƟons that call themselves to solve complex problems by breaking them into smaller, repeƟƟve sub- problems, like calculaƟng a factorial. Generator FuncƟons: FuncƟons that use the yield keyword instead of return to return an iterator that generates values one at a Ɵme, making them memory-efficient for large datasets.
In Python, a statement is a complete instrucƟon that the interpreter can execute to perform a specific acƟon. Unlike expressions, which primarily evaluate to a value, statements are the building blocks of a program that control its flow and logic.
Assignment Statements: Used to store data in variables, such as x = 10. CondiƟonals Statements: Direct the program to make decisions using if, elif and else. Looping Statements: Repeat a block of code using for or while. Control Flow Statement: Alter the execuƟon order, including break (exit loop), conƟnue (skip iteraƟon), and pass (do nothing). Import Statements: Bring in external modules or libraries, such as import math. ExcepƟon Handling: Manage errors gracefully using try and except blocks.
In Python, lists, tuples and dicƟonaries are the primary ways to store collecƟon of data. Each has unique properƟes, regarding how data is stored, accessed, and modified.
A list is an ordered, mutable collecƟon that allows duplicate elements. It is the most flexible and commonly used data structure for storing a sequence of items.
my_list = [“apple”, “banana”, “cherry”]
In Python, loop control structures are used to repeat a block of code mulƟple Ɵmes. There are two primary types of loops -for loop and while- and three main control statements- break, conƟnue, and pass- that modify their behaviour.
string, or range). It runs a fixed number of Ɵmes based on the
Category Methods DescripƟon
Case Changes
upper(), lower(), capitalize(),Ɵtle(),swapcase()
Converts text to uppercase,lowercase, or specific casing formats. Search and count
find(),index(),count(),rfind() Locates substrings or counts occurrences. Find returns -1 if not found, while index raises an error. ModificaƟon strip(),replace(),join(),split(),zfill() Removes whitespace, replaces text, joins iterables, or pads strings with zeroes.
while Loop: Repeatedly executes a code block as long as a specified condiƟon remains True. It is typically used when the number of iteraƟons is not known in advance.
break: Immediately terminate the loop and transfers execuƟon to the statement following the loop. conƟnue: Skips the remaining code in the current iteraƟons and jumps to the next cycle of the loop. pass: A null operaƟon used as a placeholder. It allows the loop to run without performing any acƟon, which is helpful when a statement is syntacƟcally required but no logic is wriƩen.
In Python, Keywords are reserved words that have predefined meanings and cannot be used as idenƟfiers (names for variables, funcƟons or classes). While there are 35 standard keywords in current, versions (like Python 3.11), they define
Python uses lines, indentaƟon and comments to define its structure, readability and logic blocks without using curly braces {}.
Theory: Python program that uses the input () funcƟon to collect informaƟon and an f-string to format the greeƟng.
Input (): This funcƟon displays a prompt to the user and waits for them to type something. By default, it saves everything as a “string” (text). F “…”: This is called an f-string (formaƫng string literal). It allows you to put variables directly inside a string by wrapping them in curly braces {}.
#Ask the user for their name name = input("Enter your name:")
#Ask the user for their age age = input("Enter your age:")
print(f"Hello{name}! It's great to meet you.I see your are {age} years old.")
Theory: We can define a list using different types by placing various values inside the square’s brackets, separated by commas.
Mixed Data Types: Unlike some languages that require all items in an array to be the same type, Python lists are versaƟle and can store different data types simultaneously- in this case, an integer, a string, a float, and a Boolean.
Features of Lists
Ordered: The items maintain the specific order in which you defined them. Mutable: You can change, add, or remove items aŌer the list has been created. Zero-Indexed: The first item is at index 0, the second at index 1, and so on.
my_list = [42, "Python",3.14, True]
print(my_list)
Theory: The code works by checking the remainder of the number when divided by 2.
input (): This asks the user to type something. Since input () always returns text (a string), we wrap it in int () to convert it into a whole number. % (Modulo Operator): It divides the number by 2 and returns only the remainder. If num % 2 is 0, it means the number is perfectly divisible by 2 (Even). If the remainder is 1, it’s not (Odd). if…else: This is a decision-maker.If the condiƟon (num % 2 ==
num = int(input("Enter a number: "))
if num % 2 == 0: print(f"{num} is Even") else: print(f"{num} is Odd")
Theory: Python has a built-in max () funcƟon that makes this even easier.
The max () funcƟon: This is a pre-installed Python tool designed to look at any number of arguments and returns the highest value among them. It replaces the enƟre if-else block with a single line of code.
num1, num2, num3 = 10, 25, 15 print(f"The largest number is {max(num1, num2,num3)}")
Theory: To print a mulƟplicaƟon table using a while loop in Python, we need a counter variable to track the iteraƟons and a condiƟon to stop the loop once you reach 10.
IniƟalizaƟon: i = 1 sets the starƟng point of your table. CondiƟon: while I <= 10 ensures the loop runs exactly ten Ɵmes. Update: i += 1 is crucial; without it, the loop would run forever (an infinite loop). F-strings: The f“{num} x {i} = {result}” syntax is a clean way to format text in python.
num = int(input("Enter the number: ")) i = 1 # Initialize the counter
print(f"Multiplication Table for {num}:")
while i <= 10: result = num * i print(f"{num} x {i} = {result}") i += 1 # Increment the counter to move to the next step
Theory: range (1, n + 1): This creates a sequence from up to 1 to 10.
“*” i : In Python, mulƟplying a string by an integer repeats that string. When i is 1, it prints one *. When i is 10, its prints 10 * ‘s.
def print_pattern(n) : for i in range (1, n + 1) : print("*")
n = 10 print_pattern(n)