-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebsite_rating.py
More file actions
22 lines (16 loc) · 1.21 KB
/
Copy pathwebsite_rating.py
File metadata and controls
22 lines (16 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# This Python code creates a dictionary called websiteInfo with keys "name," "url," "description," and "rating," each initially set to None. The code then prompts the user to input relevant values for each key using a for loop that iterates over the keys. The input values are assigned to the corresponding keys in the dictionary.
# After gathering user input, the code prints the entered values for each key in the websiteInfo dictionary using another for loop that iterates over the dictionary's items. The output displays the keys and their associated values.
websiteInfo = {"name": None, "url": None, "description": None, "rating": None}
for name in websiteInfo.keys():
websiteInfo[name] = input(f"Enter relevant values for {name}: ")
print()
for name, value in websiteInfo.items():
print(f"{name}: {value}")
startOver = input("\nWould you like to start over? (y/n): ")
if startOver.lower() == "y":
websiteInfo.clear() # Clear the dictionary
print("Dictionary cleared. You can start over.")
else:
print("Thank you for using the program!")
# NOTE 1: The .keys() method is used to return a view of all keys in a dictionary.
# NOTE 2: The .items() method returns a view of all key-value pairs in a dictionary as tuples.