Python Starred Practicals With Outputs
Python Starred Practicals With Outputs
Output:
Error: raw_input was called, but this frontend does not support input requests.
a, b = 10, 3
print("Arithmetic:", a + b)
print("Relational:", a > b)
print("Bitwise:", a & b)
print("Identity:", a is b)
Output:
Arithmetic: 13
Relational: True
Logical: True
Bitwise: 2
Identity: False
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:
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]
tpl = (1, 2, 3)
print(tpl)
print(tpl[1])
Output:
(1, 2, 3)
s = {1, 2, 3}
s.add(4)
s.remove(2)
print(s)
Output:
{1, 3, 4}
d = {'a': 1, 'b': 2}
d['c'] = 3
d.pop('a')
print(d)
Output:
{'b': 2, 'c': 3}
return a + b
print(add(2, 3))
print(add(4))
Output:
nums = [1, 2, 3, 4]
print(square)
print(sum_all)
Output:
[1, 4, 9, 16]
10
# module.py
def square(x):
return x * x
# main.py
import module
print(module.square(5))
Output:
import math
import random
print(math.sqrt(16))
print(random.randint(1, 10))
Output:
4.0
# package/module.py
def greet():
return "Hi"
# main.py
print(module.greet())
Output:
class Demo:
def show(self):
print("Hello")
d = Demo()
d.show()
Output:
Hello
class Test:
self.x = x
def display(self):
print(self.x)
t1 = Test()
t2 = Test(10)
t1.display()
t2.display()
Output:
10
class A:
class B(A):
b = B()
b.show()
Output:
class A:
b = B()
b.msg()
Output:
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
import tkinter as tk
win = tk.Tk()
win.title("My App")
win.mainloop()
Output: