RV Institute of Technology and Management, Bengaluru
Information Science and Engineering
Introduction to Python Programming
Assignment I
____________________________________________________________
Student Name: Vipin Choudhary USN/Roll No: 032
Section: D Date: 09-12-2023
_________________________________________________________________________-
Program: 01-
Creating a Restaurant Bill System using Python GUI
Program Code:
from tkinter import *
from tkinter import messagebox
def add_to_bill (item, quantity_entry, selected_items_var, total_cost_var):
quantity = quantity_entry.get()
if not [Link]() or int(quantity) <= 0:
[Link]("Warning", "Please enter a valid quantity.")
return
existing_items = selected_items_var.get()
new_item = f"{item} x{quantity}"
updated_items = existing_items + (", " + new_item if existing_items else new_item)
selected_items_var.set(updated_items)
total_cost = sum([menu_prices[[Link](' x')[0]] * int([Link](' x')[1]) for item in
selected_items_var.get().split(", ")])
total_cost_var.set("₹{:.2f}".format(total_cost))
def generate_bill(selected_items_var, total_cost_var):
___________________________________________________________________________
Course Instructor Examiner (s)
Name: Dr. Gajanan M Naik Name:
Signature: Signature:
RV Institute of Technology and Management, Bengaluru
Information Science and Engineering
Introduction to Python Programming
Assignment I
____________________________________________________________
selected_items = selected_items_var.get()
total_cost = total_cost_var.get()
if not selected_items or not total_cost:
[Link]("Warning", "Please add items to the bill before generating.")
return
bill_text = f"Bill\n\nItems: {selected_items}\nTotal Cost: {total_cost}"
bill_window = Toplevel(root)
bill_window.title("Bill")
bill_label = Label(bill_window, text=bill_text, padx=10, pady=10)
bill_label.pack()
root = Tk()
[Link]("Vipin's Restaurant Bill System")
background_image = PhotoImage(file="background_image.png")
background_label = Label(root, image=background_image)
background_label.place(relwidth=1, relheight=1)
menu_prices = {
"Dosa": 50.00,
"Iddli": 35.00,
"Samosa": 20.00,
"Burger": 80.00,
"Veg Puff": 30.00,
"Dhokla": 45.00,
___________________________________________________________________________
Course Instructor Examiner (s)
Name: Dr. Gajanan M Naik Name:
Signature: Signature:
RV Institute of Technology and Management, Bengaluru
Information Science and Engineering
Introduction to Python Programming
Assignment I
____________________________________________________________
"Chole Bhature": 60.00,
"Kachodi": 35.00,
"Veg Roll": 40.00,
"Sandwich": 30.00,
"Coke": 20.00
}
selected_items_var = StringVar()
total_cost_var = StringVar()
menu_label = Label(root, text="Menu", bg="white")
menu_label.grid(row=0, column=0, padx=10, pady=10, sticky=W)
row_num = 1
for item in menu_prices:
item_label = Label(root, text=item, bg="white")
item_label.grid(row=row_num, column=0, padx=10, pady=5, sticky=W)
quantity_entry = Entry(root)
quantity_entry.grid(row=row_num, column=1, padx=10, pady=5, sticky=W)
add_to_bill_button = Button(root, text="Add to Bill", command=lambda item=item,
quantity_entry=quantity_entry: add_to_bill(item, quantity_entry, selected_items_var,
total_cost_var), bg="white")
add_to_bill_button.grid(row=row_num, column=2, padx=10, pady=5, sticky=W)
row_num += 1
___________________________________________________________________________
Course Instructor Examiner (s)
Name: Dr. Gajanan M Naik Name:
Signature: Signature:
RV Institute of Technology and Management, Bengaluru
Information Science and Engineering
Introduction to Python Programming
Assignment I
____________________________________________________________
selected_items_label = Label(root, text="Selected Items:", bg="white")
selected_items_label.grid(row=row_num, column=0, padx=10, pady=10, sticky=W)
selected_items_display = Label(root, textvariable=selected_items_var, bg="white")
selected_items_display.grid(row=row_num, column=1, columnspan=2, padx=10, pady=10,
sticky=W)
total_cost_label = Label(root, text="Total Cost:", bg="white")
total_cost_label.grid(row=row_num+1, column=0, padx=10, pady=10, sticky=W)
total_cost_display = Label(root, textvariable=total_cost_var, bg="white")
total_cost_display.grid(row=row_num+1, column=1, columnspan=2, padx=10, pady=10,
sticky=W)
generate_bill_button = Button(root, text="Generate Bill", command=lambda:
generate_bill(selected_items_var, total_cost_var), bg="white")
generate_bill_button.grid(row=row_num+2, column=0, columnspan=3, pady=10)
[Link]()
___________________________________________________________________________
Course Instructor Examiner (s)
Name: Dr. Gajanan M Naik Name:
Signature: Signature:
RV Institute of Technology and Management, Bengaluru
Information Science and Engineering
Introduction to Python Programming
Assignment I
____________________________________________________________
Output_GUI
___________________________________________________________________________
Course Instructor Examiner (s)
Name: Dr. Gajanan M Naik Name:
Signature: Signature:
RV Institute of Technology and Management, Bengaluru
Information Science and Engineering
Introduction to Python Programming
Assignment I
____________________________________________________________
Program: 02-
Creating a Voting System using Python GUI
Program Code:
import tkinter as tk
from tkinter import messagebox
class VotingSystem:
def __init__(self, master):
[Link] = master
[Link]("Election Voting System")
[Link] = []
self.party_votes = {"BJP": 0, "Congress": 0, "JD(S)": 0}
self.name_label = [Link](master, text="Name:")
self.name_label.pack()
self.name_entry = [Link](master)
self.name_entry.pack()
self.voter_id_label = [Link](master, text="Voter ID:")
self.voter_id_label.pack()
self.voter_id_entry = [Link](master)
self.voter_id_entry.pack()
___________________________________________________________________________
Course Instructor Examiner (s)
Name: Dr. Gajanan M Naik Name:
Signature: Signature:
RV Institute of Technology and Management, Bengaluru
Information Science and Engineering
Introduction to Python Programming
Assignment I
____________________________________________________________
self.selected_party = [Link]()
self.bjp_radio = [Link](master, text="BJP", variable=self.selected_party,
value="BJP")
self.bjp_radio.pack(anchor=tk.W)
self.congress_radio = [Link](master, text="Congress",
variable=self.selected_party, value="Congress")
self.congress_radio.pack(anchor=tk.W)
self.jds_radio = [Link](master, text="JD(S)", variable=self.selected_party,
value="JD(S)")
self.jds_radio.pack(anchor=tk.W)
self.vote_button = [Link](master, text="Vote", command=self.cast_vote)
self.vote_button.pack()
self.vote_count = 0
self.max_votes = 10
def cast_vote(self):
if self.vote_count < self.max_votes:
name = self.name_entry.get()
voter_id = self.voter_id_entry.get()
selected_party = self.selected_party.get()
if name and voter_id and selected_party:
[Link]({"name": name, "voter_id": voter_id, "party": selected_party})
___________________________________________________________________________
Course Instructor Examiner (s)
Name: Dr. Gajanan M Naik Name:
Signature: Signature:
RV Institute of Technology and Management, Bengaluru
Information Science and Engineering
Introduction to Python Programming
Assignment I
____________________________________________________________
self.party_votes[selected_party] += 1
self.vote_count += 1
self.clear_entries()
if self.vote_count == self.max_votes:
self.show_results()
else:
self.show_error("Please fill in all the details.")
else:
self.show_error("Voting has ended. Results will be displayed.")
def clear_entries(self):
self.name_entry.delete(0, [Link])
self.voter_id_entry.delete(0, [Link])
self.selected_party.set("")
def show_results(self):
winner = max(self.party_votes, key=self.party_votes.get)
winner_votes = self.party_votes[winner]
tie = [party for party in self.party_votes if self.party_votes[party] == winner_votes]
if len(tie) > 1:
loser = min(self.party_votes, key=self.party_votes.get)
result_message = f"There is a tie! Mentioning the party with the least votes: {loser}"
else:
___________________________________________________________________________
Course Instructor Examiner (s)
Name: Dr. Gajanan M Naik Name:
Signature: Signature:
RV Institute of Technology and Management, Bengaluru
Information Science and Engineering
Introduction to Python Programming
Assignment I
____________________________________________________________
result_message = f"The winner is {winner} with {winner_votes} votes!"
[Link]("Election Results", result_message)
def show_error(self, message):
[Link]("Error", message)
if __name__ == "__main__":
root = [Link]()
voting_system = VotingSystem(root)
[Link]()
___________________________________________________________________________
Course Instructor Examiner (s)
Name: Dr. Gajanan M Naik Name:
Signature: Signature:
RV Institute of Technology and Management, Bengaluru
Information Science and Engineering
Introduction to Python Programming
Assignment I
____________________________________________________________
Output_GUI
___________________________________________________________________________
Course Instructor Examiner (s)
Name: Dr. Gajanan M Naik Name:
Signature: Signature:
RV Institute of Technology and Management, Bengaluru
Information Science and Engineering
Introduction to Python Programming
Assignment I
____________________________________________________________
Program: 03-
Creating a Calculator using Python GUI
Program Code:
from tkinter import *
def button_click(symbol):
current = [Link]()
[Link](0, END)
[Link](END, current + str(symbol))
def clear_entry():
[Link](0, END)
def calculate_result():
try:
result = eval([Link]())
[Link](0, END)
[Link](END, result)
except Exception as e:
[Link](0, END)
[Link](END, "Error")
window = Tk()
[Link]('''Vipin's Calculator''')
[Link](bg='#2E3B4E')
___________________________________________________________________________
Course Instructor Examiner (s)
Name: Dr. Gajanan M Naik Name:
Signature: Signature:
RV Institute of Technology and Management, Bengaluru
Information Science and Engineering
Introduction to Python Programming
Assignment I
____________________________________________________________
entry = Entry(window, width=20, font=('Helvetica', 16), borderwidth=5)
[Link](row=0, column=0, columnspan=4, padx=10, pady=10, sticky='ew')
[Link](bg='#1E2833', fg='white')
buttons = [
('7', 1, 0), ('8', 1, 1), ('9', 1, 2), ('/', 1, 3),
('4', 2, 0), ('5', 2, 1), ('6', 2, 2), ('*', 2, 3),
('1', 3, 0), ('2', 3, 1), ('3', 3, 2), ('-', 3, 3),
('0', 4, 0), ('.', 4, 1), ('=', 4, 2), ('+', 4, 3),
]
for button_text, row, col in buttons:
if button_text == '=':
button = Button(window, text=button_text, padx=20, pady=20, font=('Helvetica', 14),
command=calculate_result, bg='#3498DB', fg='white',
activebackground='#2980B9')
else:
command = lambda symbol=button_text: button_click(symbol)
button = Button(window, text=button_text, padx=20, pady=20, font=('Helvetica', 14),
command=command,
bg='#34495E', fg='white', activebackground='#2C3E50')
[Link](row=row, column=col, sticky='nsew')
clear_button = Button(window, text='C', padx=20, pady=20, font=('Helvetica', 14),
command=clear_entry,
bg='#E74C3C', fg='white', activebackground='#C0392B')
___________________________________________________________________________
Course Instructor Examiner (s)
Name: Dr. Gajanan M Naik Name:
Signature: Signature:
RV Institute of Technology and Management, Bengaluru
Information Science and Engineering
Introduction to Python Programming
Assignment I
____________________________________________________________
clear_button.grid(row=5, column=0, columnspan=4, sticky='nsew')
for i in range(5):
window.grid_rowconfigure(i, weight=1)
window.grid_columnconfigure(i, weight=1)
[Link]()
___________________________________________________________________________
Course Instructor Examiner (s)
Name: Dr. Gajanan M Naik Name:
Signature: Signature:
RV Institute of Technology and Management, Bengaluru
Information Science and Engineering
Introduction to Python Programming
Assignment I
____________________________________________________________
Output_GUI
___________________________________________________________________________
Course Instructor Examiner (s)
Name: Dr. Gajanan M Naik Name:
Signature: Signature:
RV Institute of Technology and Management, Bengaluru
Information Science and Engineering
Introduction to Python Programming
Assignment I
____________________________________________________________
Program: 04-
Creating a Student Attendance System using Python GUI
Program Code:
from tkinter import *
from tkinter import messagebox
from tkinter import ttk
class AttendanceApp:
def __init__(self, master):
[Link] = master
[Link]("Student Attendance")
[Link] = [f"Student{i}" for i in range(1, 31)]
self.attendance_status = {student: StringVar(value="Absent") for student in
[Link]}
style = [Link]()
[Link]("TLabel", background="#E1DADA")
[Link]("TRadiobutton", background="#E1DADA")
[Link]("TButton", background="#00796B", foreground="white",
font=('Helvetica', 10))
[Link] = [Link](master)
[Link](row=0, column=0, columnspan=3, pady=10)
scrollbar = [Link]([Link], orient=VERTICAL)
___________________________________________________________________________
Course Instructor Examiner (s)
Name: Dr. Gajanan M Naik Name:
Signature: Signature:
RV Institute of Technology and Management, Bengaluru
Information Science and Engineering
Introduction to Python Programming
Assignment I
____________________________________________________________
[Link] = Canvas([Link], yscrollcommand=[Link])
[Link](row=0, column=0, columnspan=3)
[Link](command=[Link])
[Link](row=0, column=3, sticky="ns")
self.students_frame = Frame([Link], bg="#E1DADA")
[Link].create_window((0, 0), window=self.students_frame, anchor="nw")
self.students_frame.bind("<Configure>", lambda e:
[Link](scrollregion=[Link]("all")))
for i, student in enumerate([Link], start=1):
label = [Link](self.students_frame, text=student, style="TLabel")
[Link](row=i, column=0, padx=10, pady=5, sticky=W)
checkbox_present = [Link](self.students_frame, text="Present",
variable=self.attendance_status[student], value="Present", style="TRadiobutton")
checkbox_present.grid(row=i, column=1, padx=10, pady=5, sticky=W)
checkbox_absent = [Link](self.students_frame, text="Absent",
variable=self.attendance_status[student], value="Absent", style="TRadiobutton")
checkbox_absent.grid(row=i, column=2, padx=10, pady=5, sticky=W)
self.submit_button = Button(master, text="Submit Attendance",
command=self.submit_attendance)
self.submit_button.grid(row=1, column=0, columnspan=3, pady=10)
def submit_attendance(self):
___________________________________________________________________________
Course Instructor Examiner (s)
Name: Dr. Gajanan M Naik Name:
Signature: Signature:
RV Institute of Technology and Management, Bengaluru
Information Science and Engineering
Introduction to Python Programming
Assignment I
____________________________________________________________
attendance_summary = "\n".join([f"{student}: {self.attendance_status[student].get()}"
for student in [Link]])
[Link]("Attendance Summary", f"Attendance
Recorded:\n{attendance_summary}")
if __name__ == "__main__":
root = Tk()
app = AttendanceApp(root)
[Link]()
___________________________________________________________________________
Course Instructor Examiner (s)
Name: Dr. Gajanan M Naik Name:
Signature: Signature:
RV Institute of Technology and Management, Bengaluru
Information Science and Engineering
Introduction to Python Programming
Assignment I
____________________________________________________________
Output_GUI
___________________________________________________________________________
Course Instructor Examiner (s)
Name: Dr. Gajanan M Naik Name:
Signature: Signature:
RV Institute of Technology and Management, Bengaluru
Information Science and Engineering
Introduction to Python Programming
Assignment I
____________________________________________________________
Program: 05-
Creating a BMI Calculator using Python GUI
Program Code:
from tkinter import *
def calculate_bmi():
weight = float(weight_entry.get())
height = float(height_entry.get()) / 100
bmi = round(weight / (height ** 2), 2)
result_label.config(text=f'Your BMI: {bmi}')
if bmi < 18.5:
category = 'Underweight'
suggestion = "You may want to gain some weight. Here are some suggestions:\n\n"\
"- Include more protein-rich foods in your diet.\n"\
"- Eat frequent, small meals throughout the day.\n"\
"- Consider strength training exercises."
elif 18.5 <= bmi < 24.9:
category = 'Normal weight'
suggestion = "Keep up the good work! Maintain a balanced diet and regular physical
activity for overall well-being."
elif 25 <= bmi < 29.9:
category = 'Overweight'
suggestion = "Consider losing some weight for better health. Here are some
suggestions:\n\n"\
"- Include more fruits and vegetables in your diet.\n"\
"- Engage in regular aerobic exercises like walking, jogging, or cycling.\n"\
___________________________________________________________________________
Course Instructor Examiner (s)
Name: Dr. Gajanan M Naik Name:
Signature: Signature:
RV Institute of Technology and Management, Bengaluru
Information Science and Engineering
Introduction to Python Programming
Assignment I
____________________________________________________________
"- Cut down on sugary and high-calorie foods."
else:
category = 'Obese'
suggestion = "It is advisable to consult a healthcare professional for personalized advice.
"\
"In the meantime, focus on a balanced diet and regular physical activity."
show_suggestions(category, suggestion)
def show_suggestions(category, suggestion):
suggestion_window = Toplevel()
suggestion_window.title(f'{category} - Suggestions')
category_label = Label(suggestion_window, text=f'Your BMI Category: {category}')
category_label.pack(pady=10)
suggestion_text = Text(suggestion_window, height=10, width=50, wrap=WORD)
suggestion_text.insert(INSERT, suggestion)
suggestion_text.pack(pady=10)
window = Tk()
[Link]('BMI Calculator')
weight_label = Label(window, text='Weight (kg):')
weight_label.grid(row=0, column=0, padx=10, pady=10)
weight_entry = Entry(window)
___________________________________________________________________________
Course Instructor Examiner (s)
Name: Dr. Gajanan M Naik Name:
Signature: Signature:
RV Institute of Technology and Management, Bengaluru
Information Science and Engineering
Introduction to Python Programming
Assignment I
____________________________________________________________
weight_entry.grid(row=0, column=1, padx=10, pady=10)
height_label = Label(window, text='Height (cm):')
height_label.grid(row=1, column=0, padx=10, pady=10)
height_entry = Entry(window)
height_entry.grid(row=1, column=1, padx=10, pady=10)
calculate_button = Button(window, text='Calculate BMI', command=calculate_bmi)
calculate_button.grid(row=2, column=0, columnspan=2, pady=10)
result_label = Label(window, text='')
result_label.grid(row=3, column=0, columnspan=2, pady=10)
[Link]()
___________________________________________________________________________
Course Instructor Examiner (s)
Name: Dr. Gajanan M Naik Name:
Signature: Signature:
RV Institute of Technology and Management, Bengaluru
Information Science and Engineering
Introduction to Python Programming
Assignment I
____________________________________________________________
Output_GUI
___________________________________________________________________________
Course Instructor Examiner (s)
Name: Dr. Gajanan M Naik Name:
Signature: Signature: