Python projects
ATM
1. def check_balance(balance):
2. print(f"\n current balance : ${balance}")
3.
4. def deposit(balance):
5. amount = float(input("Enter deposit amount: $"))
6. balance +=amount
7. print("Deposit successfully")
8. print(f"New balance: ${balance}")
9. [Link](f"deposit: ${amount}")
10. return balance
11.
12. def withdraw(balance):
13. amount = float(input("Enter amount to with draw: $"))
14. if amount > balance:
15. print("insufficient amount!")
16. print(f"Current balance: ${balance}")
17. else:
18. [Link](f"Withdraw: ${amount}")
19. balance -=amount
20. print("Withdraw successfully")
21. print(f"Remaining amount: ${balance}")
22.
23. return balance
24.
25. balance = 50000
26. secret_pin = "1234"
27. history = []
28. pin = input("Enter you PIN: ")
29. if pin == secret_pin:
30. print("Welcome")
31. while True:
32. print("------ATM------")
33. print("1. check balance")
34. print("2. Deposit")
35. print("3. Withdraw")
36. print("4. Transaction")
37. print("5. change pin")
38. print("5. Exit")
39.
40. choice = input("Enter a number: ")
41.
42. if choice == "1":
43. check_balance(balance)
44.
45. elif choice == "2":
46. balance = deposit(balance)
47.
48. elif choice == "3":
49. balance = withdraw(balance)
50.
51. elif choice == "4":
52. if len(history)==0:
53. print("No Transaction made yet")
54. else:
55. print("-----Transaction history-----")
56. for transaction in history:
57. print(transaction)
58.
59. elif choice == "5":
60. old_pin = input("Enter old pin: ")
61. if old_pin == secret_pin:
62. secret_pin = input("Enter new pin: ")
63. print("pin changed successfully")
64. else:
65. print("Incorrect pin")
66.
67. elif choice == "6":
68. print("Thank you for using ATM ")
69. break
70.
71. else:
72. print("Invalid choice! please choice 1-4")
73. else:
74. print("Wrong pin! please try again")
2. Student Grade Management System
1. students = []
2. while True:
3. print("========== Student Grade Management System ==========")
4. print("1. Add student")
5. print("2. view student")
6. print("3. search student")
7. print("4. update marks")
8. print("5. Delete marks")
9. print("6. Highest marks")
10. print("7. Average marks")
11. print("8. Grade")
12. print("9. Exit")
13.
14. choice = input("Enter an Option:")
15.
16. if choice == "1":
17. name = input("Enter student name: ")
18. course = input("Enter student course: ")
19. marks = int(input("Enter student marks: "))
20. student = {
21. "name": name,
22. "course": course,
23. "marks": marks
24.
25. }
26. [Link](student)
27. print("student added successfully")
28.
29. elif choice == "2":
30. if len(students)==0:
31. print("No student")
32. else:
33. num = 1
34. print("----student list----")
35. for student in students:
36.
37. print(f"student: {num}")
38. print("name:",student["name"])
39. print("course:", student["course"])
40. print("marks:", student["marks"])
41. num +=1
42.
43.
44. elif choice == "3":
45. search = input("Enter student name to search: ")
46. found = False
47. for student in students:
48. if [Link]()==student["name"].lower():
49. print("Student found")
50. print("name:",student["name"])
51. print("course:",student["course"])
52. print("marks:",student["marks"])
53.
54. found = True
55.
56. if found == False:
57. print("Student not found")
58.
59. elif choice == "4":
60. search = input("Enter student name to search: ")
61. found = False
62. if student["name"].lower()== [Link]():
63. new_marks = int(input("Enter new marks: "))
64. student["marks"] = new_marks
65. print("Student found and updated marks")
66. print("name:",student["name"])
67. print("course:",student["course"])
68. print("marks:",student["marks"])
69.
70. found = True
71. break
72. else:
73. print("Student not found")
74. elif choice == "5":
75. search = input("Enter student name: ")
76. found = False
77. if student["name"].lower()== [Link]():
78. found = True
79. print("student deleted successfully")
80. [Link](student)
81.
82. else:
83. print("Student to delete not found")
84.
85.
86. elif choice =="6":
87. if len(student)==0:
88. print("No student found")
89. else:
90. highest = students[0]
91. for student in students:
92. if student["marks"] > highest["marks"]:
93. highest = student
94. print("----Highest student-----")
95. print("name:", highest["name"])
96. print("course:", highest["course"])
97. print("marks:", highest["marks"])
98.
99. elif choice == "7":
100. if len(students)==0:
101. print("No student found!")
102. else:
103. total = 0
104. for student in students:
105. total += student["marks"]
106. average = total / len(students)
107. print(f"Average marks: {average:.2f}")
108.
109. elif choice == "8":
110. search = input("Enter student name: ")
111. found = False
112. for student in students:
113. if student["name"].lower()==[Link]():
114. marks = student["marks"]
115. if marks >= 90:
116. grade = "A"
117. elif marks >= 80:
118. grade >= "B"
119. elif marks >= 70:
120. grade = "C"
121. elif marks >= 60:
122. grade = "D"
123. else:
124. grade = "F"
125. print("Student :", student["name"])
126. print("Marks :", marks)
127. print("Grade :", grade)
128.
129. found = True
130. break
131. if found == False:
132. print("Student not found")
133.
134. elif choice == "9":
135. print("Thank you for using student Grade management system")
136. break
137. else:
138. print("Invalid choice. please choice 1-8")
3. Shopping Cart
1. cart = []
2. while True:
3. print("-----Shopping Cart ------")
4. print("1. Add product")
5. print("2. view cart")
6. print("3. search cart")
7. print("4. Remove cart")
8. print("5. calculate Total Bill")
9. print("6. checkout")
10. print("7. update quantity")
11. print("8. Discount")
12. print("9. VAT")
13. print("10. Exit")
14.
15. choice = input("Enter an option: ")
16. if choice == "1":
17. name = input("Enter product name: ")
18. price = int(input("Enter price: $"))
19. quantity = int(input("Enter quantity: "))
20.
21. product = {
22. "name": name,
23. "price": price,
24. "quantity": quantity
25.
26. }
27. [Link](product)
28. print("Cart Added to the shopping successfully")
29.
30. elif choice == "2":
31. if len(cart)==0:
32. print("No product found in the cart")
33.
34. else:
35. num = 1
36. print("----viewing product in the cart----")
37. for product in cart:
38. print(f"product: {num}")
39. print("name:", product["name"])
40. print("price: $",product["price"])
41. print("quantity:",product["quantity"])
42.
43. num+=1
44.
45. elif choice == "3":
46. search = input("Enter product to search: ")
47. found = False
48. for product in cart:
49. if product["name"].lower()==[Link]():
50. print("product found")
51. print("name:",product["name"])
52. print("price: $",product["price"])
53. print("Quantity", product["quantity"])
54.
55. found = True
56. if found == False:
57. print("product not found ")
58.
59. elif choice == "4":
60. search = input ("Enter product to delete: ")
61. found = False
62. for product in cart:
63. if product["name"].lower()==[Link]():
64. print("product deleted successfully")
65. [Link](product)
66. found = True
67. break
68. if found == False:
69. print("product to remove not found!")
70.
71. elif choice == "5":
72. if len(cart)==0:
73. print("No product found")
74.
75. else:
76. total = 0
77. print("----Total bill without Discount-----")
78. for product in cart:
79. total += product["price"] *
product["quantity"]
80.
81. print(f"Total bill: ${total}")
82.
83. elif choice == "6":
84. if len(cart)==0:
85. print("No product")
86. else:
87. print("=======RECEIPT========")
88. total = 0
89. for product in cart:
90. print(product["name"])
91. total += product["quantity"] *
product["price"]
92. print(f"{product['price']} X
{product['quantity']} = {product['price'] *
product['quantity']}")
93. print("----------------------")
94. print(f"Total = ${total}" )
95. print('!!THANK YOU FOR SHOPPING')
96.
97. [Link]()
98.
99. elif choice == "7":
100. search =input("Enter product name: ")
101. found = False
102. for product in cart:
103. if product["name"].lower()==[Link]():
104. new_quantity = int(input("Enter new
quantity: "))
105. product["quantity"]= new_quantity
106. print("Product found and updated the
quantity")
107. print("name:",product["name"])
108. print("price: $",product["price"])
109. print("Updated-
quantity:",product["quantity"])
110.
111. found = True
112.
113. if found == False:
114. print("product to update not found")
115.
116. elif choice == "8":
117. if len(cart)==0:
118. print("No product found")
119.
120. else:
121. total =0
122. print("discount if greater than $100000")
123. for product in cart:
124. total += product["price"] * product
["quantity"]
125. if total > 100000:
126. discount = 0.1 * total
127. final_total = total - discount
128. total = final_total
129. print(f"total: ${total}")
130.
131. elif choice == "9":
132. if len(cart)==0:
133. print("No product in the cart")
134. else:
135. total = 0
136. print("---total with discount and VAT--")
137. for product in cart:
138. total += product["price"] *
product["quantity"]
139. Vat = total * 0.18
140. after_Vat = total + Vat
141. total = after_Vat
142. if total > 100000:
143. discount = total * 0.1
144. final_total = total-discount
145. total = final_total
146. print(f"Discount after Vat: ${discount}")
147. print(f"Total after Vat: ${total}")
148.
149. elif choice == "10":
150. print("Thank you for using Shopping Cart
System.")
151. break
152.
153. else:
154. print("Invalid choice. please enter option (1-7):")
4. Library Management
1. library = []
2. while True:
3. print("========Library Management=======")
4. print("1. Add Book")
5. print("2 View Books")
6. print("3. Search Book")
7. print("4. Borrow Book")
8. print("5. Return Book")
9. print("6. Delete Book")
10. print("7. Exit")
11.
12. choice = input("Enter a number: ")
13. if choice == "1":
14. titles = input("Enter book title: ")
15. author = input("Enter the book author: ")
16. copies = int(input("how many copies: "))
17. book = {
18. "titles":titles,
19. "author":author,
20. "copies":copies
21. }
22. [Link](book)
23. print("book added successfully")
24.
25. elif choice == "2":
26. if len(library)==0:
27. print("No book found")
28.
29. else:
30. num = 1
31. print("=======view book======")
32. for book in library:
33. print(f"book: {num}")
34. print("Titles:",book["titles"])
35. print("author:",book["author"])
36. print("copies:",book["copies"])
37. num+=1
38.
39. elif choice == "3":
40. search = input("enter book to search: ")
41. found = False
42. for book in library:
43. if [Link]()==book["titles"].lower():
44. print("===book found====")
45. print("titles:",book["titles"])
46. print("author:",book["author"])
47. print("copies:",book["copies"])
48.
49. found = True
50. break
51.
52. if found == False:
53. print("Book not found!")
54.
55. elif choice == "4":
56. borrow_book = input("Enter book title to borrow: ")
57. found = False
58. for book in library:
59. if borrow_book.lower()==book["titles"]:
60. if book["copies"] > 0:
61. book["copies"] -= 1
62. print("Book borrowed successfully")
63. print("Remaining copies: ",book["copies"])
64.
65.
66. else:
67. print("No copies available")
68.
69. found = True
70.
71. if found == False:
72. print("book to borrow not found")
73.
74. elif choice == "5":
75.
76. return_book = input("Enter book to return: ")
77. found = False
78. for book in library:
79. if return_book.lower()==book["titles"].lower():
80. book["copies"] +=1
81. print("Book return successfully")
82. found = True
83.
84. if found == False:
85. print("No book found to return")
86.
87. elif choice == "6":
88. search = input("Enter a title of a book to delete: ")
89. found = False
90. for book in library:
91. if [Link]()==book["titles"].lower():
92. [Link](book)
93. print("book successfully deleted")
94. found = True
95.
96. if found == False:
97. print("Search book to delete not found")
98.
99. elif choice =="7":
100. print("Thank you for showing library management")
101. break
102. else:
103. print("Invalid Enter! Please eneter 1- 7")
5. Employee Payroll
1. employees = []
2. while True:
3. print("========== Employee Payroll ==========")
4.
5. print("1. Add Employee")
6. print("2. View Employees")
7. print("3. Search Employee")
8. print("4. Update Salary")
9. print("5. Calculate Net Salary")
10. print("6. Delete Employee")
11. print("7. Exit")
12.
13. choice = input("Enter a choice (1-7): ")
14. if choice =="1":
15. name = input("Enter employee name: ")
16. salary = float(input("Enter salary: $"))
17. allowance = float(input("Enter allowance: $"))
18. tax = float(input("Enter Tax: $"))
19.
20. employee= {
21. "name": name,
22. "salary":salary,
23. "allowance":allowance,
24. "tax":tax
25. }
26. [Link](employee)
27. print("Employee added successfully")
28.
29. elif choice == "2":
30. if len(employees)==0:
31. print("No employee found")
32. else:
33. num = 1
34. print("=====Employee List=====")
35. for employee in employees:
36. print(f"Employee: {num}")
37. print("name:",employee["name"])
38. print("salary:",employee["salary"])
39.
print("allowance",employee["allowance"])
40. print("tax:",employee["tax"])
41. num +=1
42.
43. elif choice == "3":
44. search = input("Enter employee's name: ")
45. found = False
46. for employee in employees:
47. if [Link]() ==
employee["name"].lower():
48. print("name:",employee["name"])
49. print("salary:",employee["salary"])
50.
print("allowance",employee["allowance"])
51. print("tax:",employee["tax"])
52. found = True
53.
54. if not found:
55. print("Employee not found")
56.
57. elif choice == "4":
58. employee_name = input("Enter employee name: ")
59. found = False
60. for employee in employees:
61. if employee_name.lower()==
employee["name"].lower():
62. new_salary = float(input("Enter new
salary: $"))
63. employee["salary"]=new_salary
64. print("successfully updated")
65. found = True
66.
67. if not found:
68. print("Employee not found")
69.
70. elif choice == "5":
71. if len(employees)==0:
72. print("No employee found")
73. else:
74. con = 1
75. for employee in employees:
76. net_salary = employee["salary"] +
employee["allowance"] - employee["tax"]
77. print(f"employee: {con}")
78. print("name:",employee["name"])
79. print(f"Net salary: ${net_salary: }")
80. con +=1
81.
82. elif choice == "6":
83. employee_name = input("Enter name: ")
84. found = False
85. for employee in employees:
86. if
employee_name.lower()==employee["name"].lower():
87. [Link](employee)
88. print("Employee deleted successfully")
89. found = True
90.
91. if not found:
92. print("Employee not found")
93.
94. elif choice == "7":
95. print("Thank you. employee payroll")
96. break
97.
98. else:
99. print("Invalid choice. please enter 1-7")
100.
6. Hotel Reservation System
1. hotel = []
2. while True:
3.
4. print("========== Hotel Reservation System
==========")
5.
6. print("1. Book Room")
7. print("2. View Reservations")
8. print("3. Search Guest")
9. print("4. Update Reservation")
10. print("5. Cancel Reservation")
11. print("6. Check Available Rooms")
12. print("7. Checkout Guest")
13. print("8. Exit")
14.
15. choice = input("Enter a choice (1-8): ")
16.
17. if choice == "1":
18. print("======reservation=====")
19. guest = input("Enter a guest name: ")
20. room = input("Enter a room no: ")
21. booked = False
22. for reservation in hotel:
23. if reservation["room"]==room:
24. booked = True
25. break
26.
27. if booked:
28. print("Room is already booked")
29. else:
30.
31. days = int(input("Enter number of days: "))
32. price_per_day = int(input("Enter price per
day: $"))
33.
34. reservation = {
35. "guest": guest,
36. "room": room,
37. "days": days,
38. "price_per_day": price_per_day
39. }
40. print("Hotel Booked successfully")
41. [Link](reservation)
42.
43. elif choice == "2":
44. if len(hotel) == 0:
45. print("No reservation")
46.
47. else:
48. print("Viewing reservation")
49. num = 1
50. for reservation in hotel:
51.
print("==========================")
52. print(f"reservation {num}")
53. print("guest:",reservation["guest"])
54. print("room:",reservation["room"])
55. print("days:",reservation["days"])
56.
print("price_per_day:",reservation["price_per_day"])
57. num +=1
58.
59. elif choice == "3":
60. search = input("Enter guest name: ")
61. found = False
62. for reservation in hotel:
63. if [Link]() ==
reservation["guest"].lower():
64. print("-------Search guest found----------")
65. print("guest:",reservation["guest"])
66. print("room:",reservation["room"])
67. print("days:",reservation["days"])
68.
print("price_per_day:",reservation["price_per_day"])
69. found = True
70.
71. if not found:
72. print("Guest Not found")
73.
74. elif choice == "4":
75. guest_name = input("Enter guest name: ")
76. found = False
77. for reservation in hotel:
78. if guest_name.lower() ==
reservation["guest"].lower():
79. print("--Updating searched guest ---")
80. print("1. change room")
81. print("2. change days")
82. print("3. change price_per_day")
83.
84. update = input("choose an option (1-3):
")
85.
86. if update == "1":
87. print("---Updating room---")
88. new_room = input("Enter new room:
")
89. room_taken = False
90. for reservation in hotel:
91. if
reservation["room"]==new_room:
92. # print("Room updated
successfully")
93. room_taken=True
94. break
95.
96. if room_taken:
97. print("Room taken already")
98.
99. if not room_taken:
100. reservation["room"] = new_room
101. print("successfully updated room")
102.
103. elif update == "2":
104. print("---Updating days---")
105. new_days = int(input("Enter days to
stay: "))
106. reservation["days"] = new_days
107. print("successfully updated days")
108.
109. elif update == "3":
110. print("---Updating price_per_day---")
111. new_price_per_day = int(input("Enter
new price per day: $"))
112. reservation["price_per_day"] =
new_price_per_day
113. print("successfully updated days")
114.
115. else:
116. print("Invalid choice")
117. found = True
118.
119. if not found:
120. print("Quest not found")
121.
122. elif choice == "5":
123. guest_name = input("Enter guest name: ")
124. found = False
125. for reservation in hotel:
126. if guest_name.lower() ==
reservation["guest"].lower():
127. [Link](reservation)
128. print("successfully cancelled
reservation")
129. found = True
130.
131. if not found:
132. print("quest not found")
133.
134. elif choice == "6":
135.
136. rooms =
[101,102,103,104,105,106,107,108,109,110]
137. booked_rooms = []
138. for reservation in hotel:
139.
booked_rooms.append(int(reservation["room"]))
140. print("======Available rooms
======")
141. available = False
142.
143. for room in rooms:
144. if room not in booked_rooms:
145. print(room)
146. available=True
147.
148. if not available:
149. print("no room available")
150.
151. elif choice == "7":
152. if len(hotel)==0:
153. print("No reservation found")
154. else:
155. grand_total = 0
156. toll = 1
157. print("=======RECEIPT========")
158. for reservation in hotel:
159. print(f"reservation {toll}")
160. print("guest:",reservation["guest"])
161. print("room:",reservation["room"])
162. bill = reservation["days"] *
reservation["price_per_day"]
163. print(f"Bill = ${reservation['days']} X $
{reservation['price_per_day']}: ${bill}")
164. print("----------------------")
165. toll+=1
166. grand_total += bill
167. print("-----------------------------")
168. print(f"grand-total: ${grand_total}")
169.
170. elif choice == "8":
171. print("Thank you for choosing hotel
reservation system")
172. break
173.
174. else:
175. print("invalid choice. choose (1-8)")
176.
177.
7. Safe Calculator
1. print("1. Addition")
2. print("2. Subtraction")
3. print("3. Multiplication")
4. print("4. Division")
5.
6. choice = input("Enter your choice (1-4): ")
7.
8. try:
9. first_number = int(input("Enter first number: "))
10. second_number = int(input("Enter second
number: "))
11.
12. if choice == "1":
13. result = first_number + second_number
14. symbol = " + "
15.
16.
17. elif choice == "2":
18. result = first_number - second_number
19. symbol = "-"
20.
21. elif choice == "3":
22. result = first_number * second_number
23. symbol = "*"
24.
25. elif choice == "4":
26. result = first_number / second_number
27. symbol = "/"
28.
29.
30. except ValueError:
31. print("Please enter valid numbers.")
32.
33. except ZeroDivisionError:
34. print("Cannot divide by zero.")
35.
36. else:
37. if choice in ["1","2","3","4"]:
38. if choice == "4":
39. print(f"{first_number} {symbol}
{second_number} = {result:.1f}")
40.
41. else:
42. print(f"{first_number} {symbol}
{second_number} = {result}")
43.
44. else:
45. print("Please Enter (1-4)")
46.
47. finally:
48. print("Calculator closed!")