The next one I’ll actually explain thoroughly.
So I had enough time to make another program. This time I had to meet the condtitions:
Write a Python program that checks if a key exists in a dictionary or not.
If the key exists in the dictionary, print True. Else, print False.
The key should be stored in the variable key.
Here is how I did it:
Input:
dict = {"toy": "dino", "sport": "soccer", "food": "ramen"}
key = "toy"
if key in dict:
print(True)
else:
print(False)
Output:
True
This is a shortcut:
print(dict.get(key) != None)
Which prints the same output.
Bye! See ya next time or maybe not…