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

Python - 6 To 15

The document contains examples of Python programs including calculating employee pay based on hours worked, creating a BankAccount class with deposit, withdraw, and balance methods, a bike rental program, counting words, lines, and characters in a file, extracting image links from a webpage, drawing Sierpinski triangles with recursion, drawing snowflakes with recursion, and a GUI program to calculate BMI.

Uploaded by

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

Python - 6 To 15

The document contains examples of Python programs including calculating employee pay based on hours worked, creating a BankAccount class with deposit, withdraw, and balance methods, a bike rental program, counting words, lines, and characters in a file, extracting image links from a webpage, drawing Sierpinski triangles with recursion, drawing snowflakes with recursion, and a GUI program to calculate BMI.

Uploaded by

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

6).

Develop a program that takes as input an hourly wage and the number of hours an employee worked
in the last week. The program should compute and return the employee’s pay. Overtime work is calculated
as: any hours beyond 40 but less than or equal 60 should be paid at 1.5 times the regular hourly wage.
Any hours beyond 60 should be paid at 2 times the regular hourly wage.

def pay(time, wage):


if time>60:
return 2*time*wage
elif time>40:
return 1.5*time*wage
Else:
return time*wage

time = int(input("Enter the hours worked in last week:"))


wage = float(input("Enter wage per hour:"))
print("Your's week pay is:", pay(time, wage))

7). Develop a class BankAccount that supports these methods:


a). init(): Initializes the bank account balance to the value of the input argument, or to 0 if no input
argument is given.
b). withdraw(): Takes an amount as input and withdraws it from the balance.
c). deposit(): Takes an amount as input and adds it to the balance.
d). balance(): Returns the balance on the account

class BankAccount:
def __init__(self, balance=0):
self.balances = balance

def withdraw(self, amount):


if self.balances >= amount:
self.balances -= amount
print(f"{amount} withdrawn successfully")
else:
print("Not enough balance")

def deposit(self, amount):


self.balances += amount
print(f"{amount} successfully deposited")
def balance(self):
print(f"The balance is {self.balances}")

account = BankAccount(int(input("Enter the opening balance: ")))


loop_runner = True

while loop_runner:
print("\nBank Account")
print("Operations\n 1. Withdraw\n 2. Deposit\n 3. Balance\n 4. To Exit")
option = int(input("Choice: "))

if option == 1:
account.withdraw(int(input("Enter the amount: ")))
elif option == 2:
account.deposit(int(input("Enter the amount: ")))
elif option == 3:
account.balance()
else:
loop_runner = False

8) bike rental

print("Welcome To Bike Shop")


bikes = ["MTB", "Geared", "Non-Geared", "With Training Wheels", "For Trial Riding"]

a=0
net = 0
while (a < 4):
bill = 0
print("Chooses any of the following Services\n")
a = int(input("1: View Bike onsale \n2: View Prices \n3: Place orders \n4: Exit \n"))
if a == 1:
print("The Bikes Avail are\n")
for i in bikes:
print(i)
elif a == 2:
print("The prices at our store are: \n1. Hourly----100\n2. Daily----500\n3.
Weekly---2500\n Family pack gets 30% discount on 3-5 bikes\n")
elif a == 3:
print("Choose your rental type:\n1. Hourly\n2. Daily\n3. Weekly\n")
c = int(input("Enter your option:\n"))
d = int(input("Enter the number of bikes(put within 3-5 to avail family pack option):\n"))
if c == 1:
bill += 100*d
print("Your actuall Bill is ", bill)
print("-----------------------------")
elif c == 2:
bill += 500*d
print("Your actuall Bill is ", bill)
print("-----------------------------")
elif c == 3:
bill += 2500*d
print("Your actuall Bill is ", bill)
print("-----------------------------")
else:
print("Enter a valid option")
print("-----------------------------")
if d in range(3,6):
print("Do you wanna avail family pack discount?\n")
dis = input("y for YES\nn for NO\n")
print("-----------------------------")
if dis == "y":
bill = bill*0.7
else:
bill = bill
print("Thanks for purchasing", bill, "is your bill, pay on checkout")
else:
break

9) open the file and count the number of word, line and number charecter in file

f="file.txt"
f=open("file.txt",'r')
w=0
l=0
c=0
for line in f:
word= line.split()
w+=len(word)
l+=1
c+=len(line)
print(f"number of word{w}")
print(f"number of charecter{c}")
print(f"number of line{l}")

10) image link

import requests
from bs4 import BeautifulSoup

# # Send an HTTP GET request to the webpage


url = 'https://en.wikipedia.org/wiki/Sachin_Tendulkar'

response = requests.get(url)
# Parse the HTML response with BeautifulSoup
soup = BeautifulSoup(response.content, 'html.parser')
# # Find all the image tags and extract the 'src' attribute
image_links = []
x=soup.find('img')
for i in soup.find_all('img'):
image_links.append(i['src'])
print(image_links)
12)import turtle

def draw_triangle(points, color, my_turtle):


my_turtle.fillcolor(color)
my_turtle.up()
my_turtle.goto(points[0][0], points[0][1])
my_turtle.down()
my_turtle.begin_fill()
my_turtle.goto(points[1][0], points[1][1])
my_turtle.goto(points[2][0], points[2][1])
my_turtle.goto(points[0][0], points[0][1])
my_turtle.end_fill()

def get_mid(p1, p2):


return ((p1[0] + p2[0]) / 2, (p1[1] + p2[1]) / 2)

def sierpinski(points, degree, my_turtle):


color_map = ['blue', 'red', 'green', 'white', 'yellow',
'violet', 'orange']
draw_triangle(points, color_map[degree], my_turtle)
if degree > 0:
sierpinski([points[0],
get_mid(points[0], points[1]),
get_mid(points[0], points[2])],
degree-1, my_turtle)
sierpinski([points[1],
get_mid(points[0], points[1]),
get_mid(points[1], points[2])],
degree-1, my_turtle)
sierpinski([points[2],
get_mid(points[2], points[1]),
get_mid(points[0], points[2])],
degree-1, my_turtle)

def main():
my_turtle = turtle.Turtle()
my_win = turtle.Screen()
my_points = [[0,0], [100,100], [200,0]]
sierpinski(my_points, 3, my_turtle)
my_win.exitonclick()
main()

13)

import turtle

def draw_snowflake(length, depth):


if depth == 0:
turtle.forward(length)
return
length /= 3.0
draw_snowflake(length, depth-1)
turtle.left(60)
draw_snowflake(length, depth-1)
turtle.right(120)
draw_snowflake(length, depth-1)
turtle.left(60)
draw_snowflake(length, depth-1)

turtle.speed(0)
turtle.penup()
turtle.goto(0,0)
turtle.pendown()

depth = 2 # Adjust the depth for different levels of complexity


for _ in range(3):
draw_snowflake(300, depth)
turtle.right(120)

turtle.hideturtle()
turtle.done()

15)

import tkinter as tk
def cal():
wt=float(we.get())
ht=float(he.get())
out=round(ht/(wt*2),2)
t=tk.Label(root,text="GMI")
t.grid(row=3,column=0)
ans=tk.Label(root,text=out)
ans.grid(row=3,column=1)

root=tk.Tk()

wev=tk.Label(root,text='enter the weight')


wev.grid(row=0,column=0)
we=tk.Entry(root)
we.grid(row=0,column=1)

hev=tk.Label(root,text='enter the weight')


hev.grid(row=1,column=0)
he=tk.Entry(root)
he.grid(row=1,column=1)

btn=tk.Button(root,text="click me",command=cal)
btn.grid(row=2,columnspan=2)
root.mainloop()

You might also like