0% found this document useful (0 votes)
5 views7 pages

Python Starred Practicals With Outputs

The document outlines various practical exercises in Python programming, covering topics such as displaying messages, operators, conditional statements, looping, list, tuple, set, and dictionary operations, as well as functions, modules, classes, and basic usage of libraries like Pandas and Tkinter. Each practical includes code snippets and their expected outputs, along with some error messages encountered during execution. The exercises aim to provide hands-on experience with fundamental Python concepts and functionalities.

Uploaded by

Jay U. Mahankar
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)
5 views7 pages

Python Starred Practicals With Outputs

The document outlines various practical exercises in Python programming, covering topics such as displaying messages, operators, conditional statements, looping, list, tuple, set, and dictionary operations, as well as functions, modules, classes, and basic usage of libraries like Pandas and Tkinter. Each practical includes code snippets and their expected outputs, along with some error messages encountered during execution. The exercises aim to provide hands-on experience with fundamental Python concepts and functionalities.

Uploaded by

Jay U. Mahankar
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/ 7

Practical 1: Display Message and Read Data

print("Welcome to Python Programming!")

data = input("Enter something: ")

print("You entered:", data)

Output:

Error: raw_input was called, but this frontend does not support input requests.

Practical 2: Operators in Python

a, b = 10, 3

print("Arithmetic:", a + b)

print("Relational:", a > b)

print("Logical:", a > 5 and b < 5)

print("Bitwise:", a & b)

print("Identity:", a is b)

Output:

Arithmetic: 13

Relational: True

Logical: True

Bitwise: 2

Identity: False

Practical 3: Conditional Statements

x = int(input("Enter number: "))

if x > 0:

print("Positive")

elif x < 0:

print("Negative")

else:

print("Zero")

Output:

Error: raw_input was called, but this frontend does not support input requests.
Practical 4: Looping Statements

for i in range(5):

print(i)

i = 0

while i < 5:

print(i)

i += 1

Output:

Practical 5: Loop Control Statements

for i in range(5):

if i == 3:

continue

print(i)

if i == 4:

break

Output:

4
Practical 6: List Operations

lst = [1, 2, 3]

lst.append(4)

print(lst)

lst.remove(2)

print(lst)

Output:

[1, 2, 3, 4]

[1, 3, 4]

Practical 7: Tuple Operations

tpl = (1, 2, 3)

print(tpl)

print(tpl[1])

Output:

(1, 2, 3)

Practical 8: Set Operations

s = {1, 2, 3}

s.add(4)

s.remove(2)

print(s)

Output:

{1, 3, 4}

Practical 9: Dictionary Operations

d = {'a': 1, 'b': 2}

d['c'] = 3

d.pop('a')

print(d)

Output:
{'b': 2, 'c': 3}

Practical 10: Function with Arguments

def add(a, b=0):

return a + b

print(add(2, 3))

print(add(4))

Output:

Practical 11: Lambda, Map, Reduce

from functools import reduce

nums = [1, 2, 3, 4]

square = list(map(lambda x: x**2, nums))

print(square)

sum_all = reduce(lambda x, y: x + y, nums)

print(sum_all)

Output:

[1, 4, 9, 16]

10

Practical 12: User Defined Module

# module.py

def square(x):

return x * x

# main.py

import module

print(module.square(5))

Output:

Error: No module named 'module'


Practical 13: Use of Modules

import math

import random

print(math.sqrt(16))

print(random.randint(1, 10))

Output:

4.0

Practical 14: User Defined Package

# package/module.py

def greet():

return "Hi"

# main.py

from package import module

print(module.greet())

Output:

Error: No module named 'package'

Practical 15: Class and Objects

class Demo:

def show(self):

print("Hello")

d = Demo()

d.show()

Output:

Hello

Practical 16: Constructors

class Test:

def __init__(self, x=0):

self.x = x
def display(self):

print(self.x)

t1 = Test()

t2 = Test(10)

t1.display()

t2.display()

Output:

10

Practical 17: Method Overloading/Overriding

class A:

def show(self): print("A")

class B(A):

def show(self): print("B")

b = B()

b.show()

Output:

Practical 18: Inheritance

class A:

def msg(self): print("A")

class B(A): pass

b = B()

b.msg()

Output:

Practical 19: Pandas Basics

import pandas as pd

s = pd.Series([1,2,3])
print(s)

df = pd.DataFrame({'A':[1,2], 'B':[3,4]})

print(df)

Output:

0 1

1 2

2 3

dtype: int64

A B

0 1 3

1 2 4

Practical 20: Tkinter Basics

import tkinter as tk

win = tk.Tk()

win.title("My App")

win.mainloop()

Output:

Error: no display name and no $DISPLAY environment variable

You might also like