Knowee
Questions
Features
Study Tools

write a function that accepts 10 users name and phone number and structure your data in such a way that when i input a users name it returns the phone number and if the name doesn't exist it should return 00000

Question

write a function that accepts 10 users name and phone number and structure your data in such a way that when i input a users name it returns the phone number and if the name doesn't exist it should return 00000

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a Python function that does exactly what you asked for:

def create_phonebook():
    phonebook = {}
    for i in range(10):
        name = input("Enter user's name: ")
        phone_number = input("Enter user's phone number: ")
        phonebook[name] = phone_number
    return phonebook

def get_phone_number(phonebook, name):
    return phonebook.get(name, '00000')

# usage
phonebook = create_phonebook()
print(get_phone_number(phonebook, 'John'))  # replace 'John' with the name you are looking for

In the create_phonebook function, we are creating a dictionary where the keys are the user's names and the values are their phone numbers. We are using a for loop to get the name and phone number of 10 users.

In the get_phone_number function, we are using the get method of the dictionary which returns the value for the given key if it exists in the dictionary, otherwise it returns the default value which we have set to '00000'.

This problem has been solved

Similar Questions

Complete the program below. It should:define a function thatasks the user for their first nameasks the user for their last namereturns "x y", where x is their first name and y is their last nameoutputs the result of the functionYour answer

Create a stored procedure. findStudents and write a query inside it to find a particular user(s) by their Department and display only the name and phone fields.The user name will be passed as an input to the procedure with data type VARCHAR(20).A Table named users is already been created.Sample TableNote :Table names are case-sensitive.Write only the logic for the procedure. The calling of the stored procedure and the creation of the tables are already written in the background.Input format :No console input.Output format :The output will display the names and phone numbers of the students of ECE and CIVIL departments.

You want all the users inputing the phone number field of Employee table in the format of (999)999-9999. Which of the following data validation will you use?Group of answer choicesInput MaskFace MaskFormattingDefault Value

Create two classes. The first holds customer data—specifically, a customer number and zip code. The second, a class for cities, holds the city name, state, and zip code. Additionally, each class contains a constructor that takes parameters to set the field values. Create a friend function that displays a customer number and the customer’s city, state, and zip code.Write a brief main() function to prompt the user to input customer and city information, create objects of the respective classes based on user input, and then call the friend function to display the customer information along with the associated city, state, and zip code. While calling Friend function output the statement “Calling friend function”Ensure the user provides the following details:Customer numberCity nameStateZip code

IFor a banking system, Enter the account number of length 10 and User name in a banking software as a string in input. Check whether the name = “Official”. If name is “Official” then print reverse of the account number. The user next enters a pin number as input string with a combination of Uppercase, lowercase, digits and special character as input  . Find the total number of digits and special characters in the pin number and display the count value by appending it to username and print it. Also in the pin number replace ‘_’  special character with character ‘Y’. If the user is not an Official concatenate the “user name” with string “wrong login” and print as output.

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.