AI Python for Beginners - Module 2 - book tracker assignment

Hello! I keep getting the following error message for exercise 3 of the book tracker assignment. I have created new notebooks, but still get the same error message each time that I run this cell. Please advise!

Hi @tracimor ,

Your code does not match the requirement as described in the instruction. You are required to write a if/else statement, but your code only contains if/elif and also the code logic is wrong. Below is the instruction for Ex 3:

Your Task:

Write an if/else statement that does the following:

  • If the book is overdue (meaning overdue is True), print: "Book is overdue - Contact <Borrower's name> to return it" (make sure to replace <Borrower's name> with the actual borrower’s name from the dictionary book). You should use an f-string to insert the borrower’s name.
  • Else:
    • Set the on_hold status of the book to True because you’re now placing it on hold for the next reader.
    • Print: "Book has been put on hold".
  • Use the same book variable you defined in Exercise 1.

Thanks @Kic. Can I send you my latest code to see if that is correct?

sure

Hi @tracimor ,

There are a few mistakes in your code:

  1. Incorrect access of dictionary field
  2. Wrong logic for the If statement
  3. ‘on_hold’ field is not set
  4. 2 print statements for the else statement

Python dictionary is a data type with key/value pair, here is an example to access the ‘on_hold’ field and set it to True:

book[‘on_hold’] = True

For the else statement, you only need to print a message to say that the “Book has been put on hold”

Please refer back to the lecture to check your understanding.

Also be careful with your use of indentation.
This is critical for Python code - that’s how it defines blocks of code.

You are inconsistently using single-spaces or multiple spaces.

Always using 4 spaces for indentation is a common practice.

1 Like

Please check your messages. Thanks.