Binary File Program
Binary File Program
found = False
for book in books:
if book.book_no == book_no:
book.price *= 1.1 # Increase price by 10%
found = True
if found:
with open('Book.dat', 'wb') as file:
for book in books:
pickle.dump(book, file)
print(f"Updated price of Book No {book_no} to
{book.price:.2f}")
else:
print(f"Book No {book_no} not found.")
except FileNotFoundError:
print("Book.dat file not found.")
if choice == '1':
create_file()
elif choice == '2':
display()
elif choice == '3':
author = input("Enter Author Name to count: ")
count_rec(author)
elif choice == '4':
book_no = int(input("Enter Book No to update price: "))
update(book_no)
elif choice == '5':
print("Exiting the program.")
break
else:
print("Invalid choice, please try again.")
if __name__ == "__main__":
main_menu()
'''
Menu:
1. Create File
2. Display Books
3. Count Books by Author
4. Update Book Price
5. Exit
Enter your choice: 2
Book Details:
Book No: 1001, Name: Midnight's Children, Author: Salman Rushdie, Price:
29.99
Book No: 1002, Name: The Satanic Verses, Author: Salman Rushdie, Price:
39.23
Book No: 1001, Name: Midnight's Children, Author: Salman Rushdie, Price:
29.99
Menu:
1. Create File
2. Display Books
3. Count Books by Author
4. Update Book Price
5. Exit
Enter your choice: 3
Enter Author Name to count: Salman Rushdie
Menu:
1. Create File
2. Display Books
3. Count Books by Author
4. Update Book Price
5. Exit
Enter your choice: 4
Enter Book No to update price: 1001
Updated price of Book No 1001 to 32.99
Menu:
1. Create File
2. Display Books
3. Count Books by Author
4. Update Book Price
5. Exit
Enter your choice: 5
Exiting the program.
'''