Warning! It seems that you are using Dodona within another webpage, so not everything may work properly. Let your teacher know so that he can solve the problem by adjusting a setting in the learning environment. In the meantime, you can click this link to open Dodona in a new window.
Warning! The page was not fully loaded, probably because of a network issue. It could be that not all functionalities work as expected. Please try reloading the page.
# 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()
Python sandbox
This window allows you to run Python code without installing a thing. The code you write here is not automatically submitted to Dodona.