Level 06: count controlled iterations and scope 0 of 9 activities solved
  1. 1. Countdown to launch Not yet solved
  2. 2. Rainfall Not yet solved
  3. 3. Notebook Not yet solved
  4. 4. Times tables Not yet solved
  5. 5. Voting count Not yet solved
  6. 6. Fizz Buzz Not yet solved
  7. 7. Find and replace Not yet solved
  8. 8. Twelve days of Christmas Not yet solved
  9. 9. Distribution of two dice Not yet solved
Next series Assessment point: levels 01-06
Level 06: count controlled iterations and scope

3. Notebook

Sign in to hand in your solution and get feedback.

# Notebook program # ------------------------- # Subprograms # ------------------------- def get_note_number(): valid_input = False while not valid_input: note_number = int(input("Note number: ")) if note_number >= 0 and note_number < 10: valid_input = True else: print("Invalid input. Enter 0-9.") return note_number def add_note(): index = get_note_number() note = input("Enter the note: ") notebook[index] = note def clear_notes(): choice = "" while choice not in ["y", "n"]: choice = input("Are you sure you want to delete all notes? y/n :") if choice == "y": for index in range(len(notebook)): notebook[index] = "" def order_notes(): notebook.sort() def show_notebook(): for index in range(len(notebook)): print(index, ":", notebook[index]) def menu(): print() print("a. Add note") print("c. Clear notebook") print("o. Order notes") print("q. Quit") choice = input(":") if choice == "q": return False match choice: case "a": add_note() case "c": clear_notes() case "o": order_notes() return True # ------------------------- # Main program # ------------------------- notebook = ["" for note in range(10)] running = True while running: show_notebook() running = menu()