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

Practical (Python)

Python practical pdf

Uploaded by

vtilokani1981
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)
7 views7 pages

Practical (Python)

Python practical pdf

Uploaded by

vtilokani1981
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

INDEX

SR NO. Name Of Practicals Signature

1 Implementation of numeric int

2 Implementation of float

3 Complex data types

4 Data type conversion

5 Built in function

6 If statement

7 Else statement

8 Elif statement

9 Loops statement

10 Loop manipulation using pass

11 Elseand loop block

12 Python Library function

13 Modules

14 External packages

15 Programs to implement file operations

16 GUI Forms :(Basic)

17 Adding widgets

18 Designing gui application with proper layout management


feature

1
P1: Implementation of numeric int:
Code:
a = 10
b = 20
c=a+b
print("a:",a,"type:",type(a))
print("c:",c,"type:",type(c))
Output:

P2: Implementation of float:


Code:
num = float(10)
print(num)
Output:

P3: Complex data types:


Code:
a=5
print(type(a))
b = 5.0
print(type(b))
c = 2 + 4j
print(type(c))
Output:

P4: data type conversion:


Code:
x = 10
print("x is of type:",type(x))
y = 10.6
print("y is of type:",type(y))
z=x+y
print(z)
print("z is of type:",type(z))
Output:

2
P5: Built in function:
Code:
#some more functions
def is_prime(n):
if n in [2,3]:
return True
if(n == 1) or (n % 2 == 0):
return False
r=3
while r * r <= n:
if n % r == 0:
return False
r +=2
return True
print(is_prime(78),is_prime(79))
Output:

P6: If statement:
Code:
a = 33
b = 200
if b > a:
print("b is greater than a")
Output:

P7: else statement:


Code:
for x in range(6):
print(x)
else:
print("Finally finished!")

Output:

3
P8: elif statement:
Code:
a = 33
b = 33
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
Output:

P9: loops statement:


Code:
fruits = ["apple","banana","cherry"]
for x in fruits:
print(x)
fruits = ["apple","banana","cherry"]
for x in fruits:
print(x)
if x == "banana":
break
fruits = ["apple","banana","cherry"]
for x in fruits:
if x == "banana":
continue
print(x)
Output:

P10: Loop manipulation using pass:


Code:
for i in range(5):
if i == 3:
pass #Do nothing when i is 3
else:
print(i)
Output:

4
P11: elseand loop block:
Code:
for i in range(1,4):
print(i)
else: #Executed because no break in for
print("No Break")
Output:

P12: Python Library function:


Code1:
import math
square_root = math.sqrt(4)
print("Square root of 4 is",square_root)
power = pow(2,3)
print("2 to the power 3 is",power)
Output:

Code2:
def find_square(num):
result = num*num
return result
square = find_square(3)
print('Square:',square)
Output:

P13: Modules:
Code:
from math import sqrt,factorial
print(sqrt(16))
print(factorial(6))
Output:

5
P14: External packages:
Code:
import requests
response = requests.get("https://api.github.com")
if response.status_code ==200:
print("Successfully connected to GitHub API!")
else:
print("Failed to connect to GitHub API!")
Output:

P15: Programs to implement file operations:


Code1:
file1 = open("file1.txt")
read_content = file1.read()
print(read_content)
Output:

Code2:
file1 = open('file1.txt','w')
file1.write('Programming is fun.\n')
file1.write('Programiz for beginners \n')
Output:

Code3:
file1 = open("file1.txt","r")
read_content = file1.read()
print(read_content)
file1.close()
Output:

P16: GUI Forms :(Basic)


Code:
from tkinter import*
root = Tk()
root.title("Welcome to GeekForGeeks")
root.geometry('350x200')
root.mainloop()
Output:

6
P17: Adding widgets:
Code:
from tkinter import*
root = Tk()
frame = Frame(root)
frame.pack()
button = Button(frame,text='Geek')
button.pack()
root.mainloop()

Output:

P18: Designing gui application with proper layout management feature:


Code:
import tkinter as tk
def submit_entry():
user_input=entry.get()
window=tk.Tk()
window.title("my simple")

label=tk.Label(window, text="My GUI FORM")


label.pack(pady=20)
label=tk.Label(window, text="this is some text")
label.pack()
entry=tk.Entry(window)
entry.pack(pady=5)
button=tk.Button(window, text="click")
button.pack(pady=10)

window.mainloop()
Output:

You might also like