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

Python Experiments

The document outlines a series of six experiments aimed at teaching Python programming concepts, including executing simple programs, understanding data types, arithmetic operators, data type conversion, and currency and data size conversions. Each experiment includes an aim, objective, software requirements, theoretical background, program examples, test cases, and results. The experiments are designed to provide hands-on experience with Python programming in various contexts.

Uploaded by

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

Python Experiments

The document outlines a series of six experiments aimed at teaching Python programming concepts, including executing simple programs, understanding data types, arithmetic operators, data type conversion, and currency and data size conversions. Each experiment includes an aim, objective, software requirements, theoretical background, program examples, test cases, and results. The experiments are designed to provide hands-on experience with Python programming in various contexts.

Uploaded by

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

‭Experiment No.

1‬

‭Aim :‬‭Execute a Python Program.‬

‭Objective :‬‭Write and Execute a Simple Python Program.‬

‭Software Requirements :‬‭Python3, IDE (VS Code / Google Colab / Anaconda)‬

‭Theory:‬
‭1.‬ ‭Python Scripts have the file extension .py‬
‭2.‬ ‭Any IDE like VS Code / Google Colab / Anaconda can be used for executing Python‬
‭Scripts.‬

‭Program :‬

‭#Execution of a Simple Python Program.‬

‭print(“Hello world !”)‬

‭Test Cases:‬

‭ estCase-1:‬
T
‭Hello world !‬

‭Result :‬‭Executed a Simple Python Program Successfully.‬


‭Experiment No. 2‬

‭Aim :‬ ‭Learn Python Data Types.‬

‭Objective :‬‭Write and Execute a Simple Python Program to print Python Data Types.‬

‭Software Requirements :‬‭Python3, IDE (VS Code / Google‬‭Colab / Anaconda)‬

‭ heory:‬
T
‭Python Data types are the classification or categorization of data items. Data types represent‬
‭the kind of value , and operations can be performed on a particular data.Since everything is an‬
‭object in Python programming, Python data types are classes and variables are instances‬
‭(objects) of these classes. The following are the standard or built-in data types in Python:‬
‭●‬ ‭Numeric – int, float, complex‬
‭●‬ ‭Sequence Type – string, list, tuple‬
‭●‬ ‭Mapping Type – dict‬
‭●‬ ‭Boolean – bool‬
‭●‬ ‭Set Type – set, frozenset‬
‭●‬ ‭Binary Types –‬‭bytes‬‭,‬‭bytearray‬‭,‬‭memoryview‬

‭Program :‬

‭# integer numbers‬
‭a =‬‭5‬
‭print‬‭(a,‬‭type‬‭(a))‬

‭# floating numbers‬
‭b =‬‭5.0‬
‭print‬‭(b,‬‭type‬‭(b))‬

‭# complex numbers‬
‭c =‬‭2‬‭+‬‭4j‬
‭print‬‭(c,‬‭type‬‭(c))‬

‭# list with int values‬


‭lst = [‬‭1‭,‬‬‭2‬‭,‬‭3‬‭]‬
‭print‬‭(lst,‬‭type‬‭(lst))‬

‭# tuple with int values‬


‭tpl = (‬‭1‭,‬‬‭2‭,‬‬‭3‭)‬ ‬
‭print‬‭(tpl,‬‭type‬‭(tpl))‬

‭# set with int values‬


‭st = {‬‭1‭,‬‬‭2‬‭,‬‭3‭}‬ ‬
‭print‬‭(st,‬‭type‬‭(st))‬

‭# dictionary with int values‬


‭dct = {‬‭'21154-cm-001'‬‭:‬‭'suresh'‬‭,‬‭'21154-cm-002'‬‭:‬‭'ramesh'‬‭,‬‭'21154-cm-003'‬‭:‬‭'havesh'‬‭}‬
‭print‬‭(dct,‬‭type‬‭(dct))‬

‭Test Cases:‬

‭ estCase-1:‬
T
‭5 <class 'int'>‬
‭5.0 <class 'float'>‬
‭(2+4j) <class 'complex'>‬
‭[1, 2, 3] <class 'list'>‬
‭(1, 2, 3) <class 'tuple'>‬
‭{1, 2, 3} <class 'set'>‬
‭{'21154-cm-001': 'suresh', '21154-cm-002': 'ramesh', '21154-cm-003': 'havesh'} <class 'dict'>‬

‭Result :‬‭Successfully executed a Python program involving Data types.‬


‭Experiment No. 3‬

‭Aim :‬‭Execute Arithmetic Operators in Python.‬

‭Objective :‬‭Write and Execute Arithmetic Operators in Python.‬

‭Software Requirements :‬‭Python3, IDE (VS Code / Google‬‭Colab / Anaconda)‬

‭ heory:‬
T
‭The standard arithmetic operators in Python are:‬

‭‬
● ‭ ‬‭: Addition‬
+
‭●‬ ‭-‬‭Subtraction‬
‭●‬ ‭\*‬‭: Multiplication‬
‭●‬ ‭/‭:‬ Division‬
‭●‬ ‭//‬‭: Floor division‬
‭●‬ ‭%‬‭: Modulus‬
‭●‬ ‭**** Exponentiation‬

‭Program :‬

‭# Arithmetic Operators in Python‬

‭ Addition‬
#
‭addition = 10 + 5‬
‭print(f"Addition (10 + 5): {addition}")‬

‭ Subtraction‬
#
‭subtraction = 10 - 5‬
‭print(f"Subtraction (10 - 5): {subtraction}")‬

‭ Multiplication‬
#
‭multiplication = 10 * 5‬
‭print(f"Multiplication (10 * 5): {multiplication}")‬

‭ Division‬
#
‭division = 10 / 5‬
‭print(f"Division (10 / 5): {division}")‬

‭ Modulus‬
#
‭modulus = 10 % 3‬
‭print(f"Modulus (10 % 3): {modulus}")‬
‭ Exponentiation‬
#
‭exponentiation = 2 ** 3‬
‭print(f"Exponentiation (2 ** 3): {exponentiation}")‬

‭ Floor Division‬
#
‭floor_division = 10 // 3‬
‭print(f"Floor Division (10 // 3): {floor_division}")‬

‭Test Cases:‬

‭ estCase-1:‬
T
‭Addition (10 + 5): 15‬
‭Subtraction (10 - 5): 5‬
‭Multiplication (10 * 5): 50‬
‭Division (10 / 5): 2.0‬
‭Modulus (10 % 3): 1‬
‭Exponentiation (2 ** 3): 8‬
‭Floor Division (10 // 3): 3‬

‭Result :‬‭Successfully Executed a Python program involving arithmetic operators.‬


‭Experiment No. 4‬

‭Aim :‬‭Execute Data Type conversion in Python.‬

‭Objective :‬‭Write and Execute Data type conversion in Python.‬

‭Software Requirements :‬‭Python3, IDE (VS Code / Google‬‭Colab / Anaconda)‬

‭ heory:‬
T
‭Data type conversion in Python refers to the process of converting one data type to another.‬
‭The user manually converts a data type using functions like‬‭int()‬‭,‬‭float()‬‭,‬‭str()‬‭,‬‭list()‬‭, etc. This is‬
‭necessary to ensure compatibility between operations. Proper type conversion prevents errors‬
‭and ensures accurate data handling.‬

‭Program :‬

‭# Data Type Conversion Examples‬

‭ Integer to Float‬
#
‭int_to_float = float(10)‬
‭print(f"Integer to Float: {int_to_float}")‬

‭ Float to Integer‬
#
‭float_to_int = int(10.7)‬
‭print(f"Float to Integer: {float_to_int}")‬

‭ Integer to String‬
#
‭int_to_str = str(10)‬
‭print(f"Integer to String: {int_to_str}")‬

‭ String to Integer‬
#
‭str_to_int = int("10")‬
‭print(f"String to Integer: {str_to_int}")‬

‭ String to Float‬
#
‭str_to_float = float("10.5")‬
‭print(f"String to Float: {str_to_float}")‬

‭Test Cases:‬
‭ estCase-1:‬
T
‭Integer to Float: 10.0‬
‭Float to Integer: 10‬
‭Integer to String: 10‬
‭String to Integer: 10‬
‭String to Float: 10.5‬

‭Result :‬‭Successfully executed a Python Program involving Data type conversion in Python.‬
‭Experiment No. 5‬

‭Aim :‬‭Execute Arithmetic Operations in Python.‬

‭Objective :‬‭Write and Execute a Python Program to convert US Dollars to Indian Rupee.‬

‭Software Requirements :‬‭Python3, IDE (VS Code / Google‬‭Colab / Anaconda)‬

‭Theory:‬
‭1.‬ ‭The currency conversion process involves multiplying the amount in US dollars by the‬
‭current exchange rate of the Indian Rupee.‬
‭2.‬ ‭For example, if 1 USD = 85.62 INR, then 10 USD will be equivalent to 856.2 INR.‬

‭Program :‬

‭ Input: Amount in USD and the exchange rate‬


#
‭usd_amount = float(input("Enter amount in US Dollars: "))‬
‭exchange_rate = 85.62‬

‭ Conversion‬
#
‭inr_amount = usd_amount * exchange_rate‬

‭ Output‬
#
‭print(f"{usd_amount} USD is equivalent to {inr_amount:.2f} INR.")‬

‭Test Cases:‬

‭ estCase-1:‬
T
‭Enter amount in US Dollars: 20‬
‭20.0 USD is equivalent to 1712.40 INR.‬

‭ estCase-2:‬
T
‭Enter amount in US Dollars: 55‬
‭55.0 USD is equivalent to 4709.10 INR.‬

‭Result :‬‭Successfully Executed a Python Program of converting USD to INR.‬


‭Experiment No. 6‬

‭Aim :‬‭Execute Arithmetic Operations in Python.‬

‭ bjective :‬‭Write and Execute a Python Program to convert bits to MegaBytes, GigaBytes and‬
O
‭TeraBytes.‬

‭Software Requirements :‬‭Python3, IDE (VS Code / Google‬‭Colab / Anaconda)‬

‭ heory:‬
T
‭Data is measured in bits, bytes, kilobytes, megabytes, gigabytes, and terabytes.‬
‭Conversion from bits to higher units involves dividing by specific powers of 2 or 10, depending‬
‭on the context.‬
‭In this program, we use the binary system for conversion:‬
‭1 Byte = 8 bits‬
‭1 KB = 1024 Bytes‬
‭1 MB = 1024 KB‬
‭1 GB = 1024 MB‬
‭1 TB = 1024 GB‬

‭Program :‬

‭ Input: Number of bits‬


#
‭bits = int(input("Enter the number of bits: "))‬

‭ ytes_ = bits / 8‬
b
‭kilobytes = bytes_ / 1024‬
‭megabytes = kilobytes / 1024‬
‭gigabytes = megabytes / 1024‬
‭terabytes = gigabytes / 1024‬

‭# Output‬
‭print‬‭(‬‭f‭"‬ ‬‭{bits}‬‭bits is equivalent to:"‬‭)‬
‭print‬‭(‬‭f‭"‬ Bytes‬‭{‬‭bytes‬‭}‬‭"‬‭)‬
‭print‬‭(‬‭f‭"‬ KiloBytes‬‭{kilobytes}‬‭"‭)‬ ‬
‭print‬‭(‬‭f‭"‬ MegaBytes‬‭{megabytes}‬‭"‬‭)‬
‭print‬‭(‬‭f‭"‬ GigaBytes‬‭{gigabytes}‬‭"‭)‬ ‬
‭print‬‭(‬‭f‭"‬ TeraBytes‬‭{terabytes}‬‭"‬‭)‬
‭Test Cases:‬

‭ estCase-1:‬
T
‭Enter the number of bits: 356489‬
‭356489 bits is equivalent to:‬
‭Bytes 44561.125‬
‭KiloBytes 43.5167236328125‬
‭MegaBytes 0.04249680042266846‬
‭GigaBytes 4.1500781662762165e-05‬
‭TeraBytes 4.052810709254118e-08‬

‭ esult :‬‭Successfully Executed a Python Program to convert bits to MegaBytes, GigaBytes and‬
R
‭TeraBytes.‬

You might also like