Respuesta :
Answer:
Okay. I am doing it with Python. Hope it'll help you to understand the concept.
Code:
the_dict={} #Creating a dictonary
def dat(): # Creating a function named dat()
name = input('Your Name: ') # Data from user
ph = input('Phone Number: ')
for i in range(1): #Creating loop
the_dict[name]=ph # Placing the value in dictonary
more = input('More Data (y/n): ') # Asking for More data
if more == 'y': # if more is y then run the function dat()
dat() # calling dat()
elif more == 'n': # if more is n then print the dictonary named 'the_dict'
print(the_dict)
else:
print('Wrong Input') # if wrong input print the message and run dat() again
dat()
dat() # calling the function
Result:
Your Name: PyMan
Phone Number: 9814579063
More Data (y/n): y
Your Name: PyMman2
Phone Number: 451513262026
More Data (y/n): y
Your Name: C#Man
Phone Number: 7798822222
More Data (y/n): n
{'PyMan': '9814579063', 'PyMman2': '451513262026', 'C#Man': '7798822222'}
Below is the required Python code.
Python
Program:
#Creating a dictionary
the_dict={}
#Creating a function
def dat():
#Input data
name = input('Your Name: ')
ph = input('Phone Number: ')
#Creating a loop
for i in range(1):
#Placing the value in dictionary
the_dict[name]=ph
#Asking the user for more data
more = input('More Data (y/n): ')
#Run the function, of more is "y"
if more == 'y':
#Calling the function dat()
dat()
#Print the dictionary named "the_dict", if more is "n"
elif more == 'n':
print(the_dict)
else:
#Print the message and run the function, if wrong
print('Wrong Input')
dat()
#Function calling
dat()
Program explanation:
- Creating a dictionary and function.
- Input data.
- Creating a loop.
- Placing the value in dictionary.
- Asking the user for more data.
- Run the function, of more is "y".
- Calling the function.
- Print the dictionary named "the_dict", if more is "n".
- Print the message and run the function, if wrong
Output:
Find below the attachment of program output.
Find out more information about Python here:
https://brainly.com/question/26497128
