This is the question:
and this the output that is required:
This is code I have written so far:
class_list = []
keys = []
meanings = []
def script():
key = input("Enter the word: ")
no_meanings = int(input("\nEnter the no of meanings: "))
meanings.append(no_meanings)
keys.append(key)
print(keys)
print(meanings)
print("\nEnter the meanings: ")
for i in range(no_meanings):
listVal = input()
class_list.append(listVal)
text = '\n'.join(class_list)
if(no_meanings <= 0):
print("Invalid Input")
if(len(keys) == 1):
print("Here's the dictionary you've created: " )
for i in range(len(keys)):
for i in range((len(meanings))):
print(keys[i] + ":" + str(class_list[:int(meanings[i])]))
del class_list[:int(meanings[i])]
else:
print("Here's the dictionary you've created: " )
for i in range(len(keys)):
for x in range((len(meanings)//2)):
print(keys[i] + ":" + str(class_list[:int(meanings[x])]))
del class_list[:int(meanings[x])]
try:
restart = input("Do you want to add one more elements to the dictionary? If yes, press 1, else press 0: \n")
except EOFError:
exit()
if restart == "1":
script()
elif restart == "0":
if(len(keys) == 1):
print("Here's the dictionary you've created: " )
for i in range(len(keys)):
for i in range((len(meanings))):
print(keys[i] + ":" + str(class_list[:no_meanings]))
del class_list[:no_meanings]
else:
print("Here's the dictionary you've created: " )
for i in range(len(keys)):
for x in range((len(meanings)//2)):
print(keys[i] + ":" + str(class_list[:no_meanings]))
del class_list[:no_meanings]
else:
print("Invalid Input")
print("Here's the dictionary you've created: ")
for i in range(len(keys)):
for i in range((len(meanings))):
print(keys[i] + ": " + str(class_list[:no_meanings]))
del class_list[:no_meanings]
script()
This code doesn't works well when i keep on adding the words and meanings but when I enter no. of meanings as "0". It doesn't print the previously entered words and meanings.
I am a beginner to the programming world and have been working on this for DAYSSS but i still can't able to figure out the logic.