Else with for loop in Python

PHOTO EMBED

Fri Sep 01 2023 10:29:09 GMT+0000 (Coordinated Universal Time)

Saved by @pythonHub #python #python-hub #basics

find_item = input("Enter the item to be searched here:- ").lower()

items = {'wand': 5, 'telescope': 2, 'feather pen': 7}

for thing in items:
    if thing == find_item:
        print(f"{items[thing]} units of {thing} are present.")
        break
else:
    print('No stock left! You need to go and buy!!')
content_copyCOPY