[go: up one dir, main page]

0% found this document useful (0 votes)
21 views18 pages

AD Lab

The document outlines a series of Python programming assignments for a laboratory course, including tasks such as variable initialization, type analysis, basic arithmetic operations, and user input handling. Each program is accompanied by source code examples and expected outputs. The assignments aim to enhance students' understanding of Python fundamentals and practical coding skills.

Uploaded by

agrawalnitin4177
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views18 pages

AD Lab

The document outlines a series of Python programming assignments for a laboratory course, including tasks such as variable initialization, type analysis, basic arithmetic operations, and user input handling. Each program is accompanied by source code examples and expected outputs. The assignments aim to enhance students' understanding of Python fundamentals and practical coding skills.

Uploaded by

agrawalnitin4177
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Applications Development Laboratory (CS33002), Spring 202

Applications Development Laboratory (ADL)


Individual Work
LLab. No: 1 , Assignment No.: 0.1, Date:11.12.2024, Day: WEDNESDAY
Topic: Basics of Pythons
Roll Number: 22051619 Branch/Section: CSE 19
Name in Capital: Shipra Singh

(Instruction: Rename this file as r-AD Lab-x where r is your roll number & x is your lab. number &
Suppose your roll number is 1905123 & you want to submit lab-2 programs, then file name should be
1905123-AD Lab-2. Finally delete all texts inside parentheses, also parenthesis)

Program No: 01.1

Program Title: Initialize some variables in the python workspace. Now analyze and display what

are variables are created, then delete the single variable as well as all the created

variables.

Input/Output Screenshots:

RUN-1:

Page
Applications Development Laboratory (CS33002), Spring 202

Source code

a = 10

b = 20

c = "Hello, World!"

d = [1, 2, 3, 4]

e = {"key": "value"}
Page
Applications Development Laboratory (CS33002), Spring 202
print("Variables in the workspace:")

print({k: v for k, v in globals().items() if not k.startswith("_") and k not in ["__builtins__",


"print", "input"]})

del a

print("\nAfter deleting variable 'a':")

print({k: v for k, v in globals().items() if not k.startswith("_") and k not in ["__builtins__",


"print", "input"]})

for var in list(globals()):

if not var.startswith("_") and var not in ["__builtins__", "print", "input", "del"]:

del globals()[var]

print("\nAfter deleting all variables:")

print({k: v for k, v in globals().items() if not k.startswith("_") and k not in ["__builtins__",


"print", "input"]})

Program No: 01.2

Program Title: Initialize some variables with different types of value. Now analyze what is the

type of those variables

Input/Output Screenshots:

RUN-1:

Page
Applications Development Laboratory (CS33002), Spring 202

Source code

integer_value = 10

float_value = 20.5

string_value = "Hello, Python!"

boolean_value = True

complex_value = 3 + 4j

list_value = [1, 2, 3, 4, 5]

tuple_value = (6, 7, 8, 9)

set_value = {10, 20, 30, 40}

dictionary_value = {"name": "Alice", "age": 25}

# Analyzing and displaying the types of the variables

print("Variable Types:")

print(f"integer_value: {integer_value}, Type: {type(integer_value)}")

print(f"float_value: {float_value}, Type: {type(float_value)}")

print(f"string_value: {string_value}, Type: {type(string_value)}")


Page
Applications Development Laboratory (CS33002), Spring 202
print(f"boolean_value: {boolean_value}, Type: {type(boolean_value)}")

print(f"complex_value: {complex_value}, Type: {type(complex_value)}")

print(f"list_value: {list_value}, Type: {type(list_value)}")

print(f"tuple_value: {tuple_value}, Type: {type(tuple_value)}")

print(f"set_value: {set_value}, Type: {type(set_value)}")

print(f"dictionary_value: {dictionary_value}, Type: {type(dictionary_value)}")

Program No: 01.3

Program Title: Write an python code to initialize your roll no., name and branch then display all

the details

Input/Output Screenshots:

RUN-1:

Page
Applications Development Laboratory (CS33002), Spring 202

Source code

roll_no = 22051619
name = "Shipra "
branch = "Computer Science"

print("Student Details:")
print(f"Roll Number: {roll_no}")
print(f"Name: {name}")
print(f"Branch: {branch}")

Program No: 01.4

Program Title:Write an python to initialize two variables, then find out the sum, multiplication,

subtraction and division of them.

Input/Output Screenshots:

RUN-1:

Source code

num1 = 10

num2 = 5

Page
Applications Development Laboratory (CS33002), Spring 202

sum_result = num1 + num2

multiplication_result = num1 * num2

subtraction_result = num1 - num2

if num2 != 0:

division_result = num1 / num2

else:

division_result = "Undefined (cannot divide by zero)"

print(f"Sum: {sum_result}")

print(f"Multiplication: {multiplication_result}")

print(f"Subtraction: {subtraction_result}")

print(f"Division: {division_result}")

Program No: 01.5

Program Title: Write an python code to enter a 3 numbers from the keyboard, then find out sum

of all the 3 numbers. Write an python code to enter the radius of a circle, then

calculate the area and circumference of the circle.

Page
Applications Development Laboratory (CS33002), Spring 202

Input/Output Screenshots:

RUN-1:

Source code

num1 = float(input("Enter the first number: "))

num2 = float(input("Enter the second number: "))

num3 = float(input("Enter the third number: "))

# Calculate the sum

sum_of_numbers = num1 + num2 + num3

# Print the result

print(f"The sum of the three numbers is: {sum_of_numbers}")

Page
Applications Development Laboratory (CS33002), Spring 202

Program No: 01.6

Program Title: Write an python code to calculate the compound interest of the given P, T, R

Input/Output Screenshots:

RUN-1:

Source code

P = float(input("Enter the principal amount (P): "))

T = float(input("Enter the time period in years (T): "))


Page
Applications Development Laboratory (CS33002), Spring 202
R = float(input("Enter the annual rate of interest (R in %): "))

CI = P * (1 + R / 100) ** T - P

print(f"The compound interest is: {CI:.2f}")

Program No: 01.7

Program Title: Write an python code to enter two numbers from the keyboard, then swap them

without using 3rd variable.

Input/Output Screenshots:

RUN-1:

Page
Applications Development Laboratory (CS33002), Spring 202

Source code

num1 = float(input("Enter the first number: "))

num2 = float(input("Enter the second number: "))

print(f"Before swapping: num1 = {num1}, num2 = {num2}")

num1, num2 = num2, num1

print(f"After swapping: num1 = {num1}, num2 = {num2}")

Program No: 01.8

Program Title: Write an python code to enter two numbers and implement all the relational

operators on that two numbers.

Input/Output Screenshots:

RUN-1:

Page
Applications Development Laboratory (CS33002), Spring 202

Source code

num1 = float(input("Enter the first number: "))

num2 = float(input("Enter the second number: "))

print(f"\nResults of relational operations on {num1} and {num2}:")

print(f"{num1} > {num2} : {num1 > num2}")

print(f"{num1} < {num2} : {num1 < num2}")

print(f"{num1} >= {num2} : {num1 >= num2}")

print(f"{num1} <= {num2} : {num1 <= num2}")

print(f"{num1} == {num2} : {num1 == num2}")

print(f"{num1} != {num2} : {num1 != num2}")


Page
Applications Development Laboratory (CS33002), Spring 202

Program No: 01.9

Program Title: Write an python code to convert given paisa into its equivalent rupee and paisa as

per the following format. 550 paisa = 5 Rupee and 50 paisa.

Input/Output Screenshots:

RUN-1:

Source code

paisa = int(input("Enter the amount in paisa: "))

rupees = paisa // 100

remaining_paisa = paisa % 100

print(f"{paisa} paisa = {rupees} Rupee and {remaining_paisa} paisa")

Page
Applications Development Laboratory (CS33002), Spring 202

Program No: 01.10

Program Title: Write an python code to convert given second into its equivalent hour, minute

And second as per the following format. Example. 7560 second = 2 Hour, 27

Minute and40 Second.

Input/Output Screenshots:

RUN-1:

Source code

total_seconds = int(input("Enter the time in seconds: "))

hours = total_seconds // 3600

remaining_seconds = total_seconds % 3600

minutes = remaining_seconds // 60

seconds = remaining_seconds % 60

print(f"{total_seconds} second = {hours} Hour, {minutes} Minute and {seconds} Second.")

Page
Applications Development Laboratory (CS33002), Spring 202

Program No: 01.11

Program Title: Write an python code to convert a quantity in meter entered through keyboard

into its equivalent kilometer & meter as per the following format. Example - 2430

meter = 2 Km and 430 meter.

Input/Output Screenshots:

RUN-1:

Source code

total_meters = int(input("Enter the distance in meters: "))

kilometers = total_meters // 1000

remaining_meters = total_meters % 1000

print(f"{total_meters} meter = {kilometers} Km and {remaining_meters} meter.")

Program No: 01.12

Page
Applications Development Laboratory (CS33002), Spring 202
Program Title: A cashier has currency notes of denominations 10, 50 and 100. If the amount to

be withdrawn is input through the keyboard in hundreds, write an python code to

find the total number of currency notes of each denomination the cashier will

have to give to the with drawer . Ramesh’s basic salary is input through the

keyboard. His dearness allowance is 40% of basic salary, and house rent

allowance is 20% of basic salary. Write an python code to calculate his gross

salary

Input/Output Screenshots:

RUN-1:

Source code

amount = int(input("Enter the amount to withdraw (in hundreds): "))

Page
Applications Development Laboratory (CS33002), Spring 202

if amount % 10 != 0:

print("Invalid amount. Please enter an amount in multiples of 10.")

else:

notes_100 = amount // 100

remaining_amount = amount % 100

notes_50 = remaining_amount // 50

remaining_amount %= 50

notes_10 = remaining_amount // 10

# Display the result

print(f"100 notes: {notes_100}, 50 notes: {notes_50}, 10 notes: {notes_10}")

For finding Ramesh’s gross salary

basic_salary = float(input("Enter Ramesh's basic salary: "))

dearness_allowance = 0.40 * basic_salary

Page
Applications Development Laboratory (CS33002), Spring 202
house_rent_allowance = 0.20 * basic_salary

gross_salary = basic_salary + dearness_allowance + house_rent_allowance

print("\nRamesh's Salary Details:")

print(f"Basic Salary: {basic_salary}")

print(f"Dearness Allowance (40%): {dearness_allowance}")

print(f"House Rent Allowance (20%): {house_rent_allowance}")

print(f"Gross Salary: {gross_salary}")

Page

You might also like