Level 06: count controlled iterations and scope 0 van 9 activiteiten opgelost
  1. 1. Countdown to launch Nog niet opgelost
  2. 2. Rainfall Nog niet opgelost
  3. 3. Notebook Nog niet opgelost
  4. 4. Times tables Nog niet opgelost
  5. 5. Voting count Nog niet opgelost
  6. 6. Fizz Buzz Nog niet opgelost
  7. 7. Find and replace Nog niet opgelost
  8. 8. Twelve days of Christmas Nog niet opgelost
  9. 9. Distribution of two dice Nog niet opgelost
Volgende reeks Assessment point: levels 01-06
Level 06: count controlled iterations and scope

3. Notebook

Meld je aan om je oplossing in te dienen en feedback te krijgen.

# 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()