Write robust python code that take from the user the name of file to open.
Then, take name from the user to search inside the file then display its phone number if found
Code:
def fetch_phone_number():
# Enter the file name which you wish to open
filename = input("Enter the filename to be opened")
dict = {}
try:
# Open the file in read mode
with open(filename, 'r') as fp:
# read the file line by line
line = fp.readline()
while line:
line = line.split()
# storeall the usernames with phone numbers in a dictionary
dict.update({line[0]: line[1]})
line = fp.readline()
# If user exist print the phone number
# otherwise handle the exception
user_name = input("Enter the user_name to be searched")
if dict.get(user_name) is not None:
print(dict.get(user_name))
else:
print("User does not exist")
except FileNotFoundError:
print("File does not exist")
fetch_phone_number()





Write robust python code that take from the user the name of file to open. Then,...
IN PYTHON Write a block of code that prompts the user for two filenames. Open the first file, display # its contents to the screen but redirect the content to the second file.
IN PYTHON Write a program that asks the user for the name of a file . The program should display the contents of any file with each line preceded with a line number followed by a colon. The line number should start at 1
Write a Python program which prompts the user for a file name then a sentence. Display the number of characters in the sentence and save the sentence to the file name. If the file already exists, ask the user if the file should be overwritten.
USING PYTHON!!!! Follow the instructions below: 1. Open a file and write the following to a file: Your Name INSS 250 Final Each should be on a new line. 2. With the file open, take input from a user and append it to the file. It can be any input but must be at least 10 words. I suggest do it in a loop. 3. Now as we did in class, use the file as input to count the number...
python code:
Task 1: Write a Python program that takes as input from the user the name of a file containing postcode/location information. Each line in the file consists of the postcode followed by a tab followed by a comma-separated list of locations that have that postcode. For example, the file Small.txt contains: 3015 Newport,South Kingsville,Spotswood 3016 Williamstown 3018 Altona,Seaholme 3019 3021 Albanvale,Kealba,Kings Park,St Albans Braybrook, Robinson Your program should create a list of postcode/location pairs with each pair stored...
Write a program **(IN C)** that displays all the phone numbers in a file that match the area code that the user is searching for. The program prompts the user to enter the phone number and the name of a file. The program writes the matching phone numbers to the output file. For example, Enter the file name: phone_numbers.txt Enter the area code: 813 Output: encoded words are written to file: 813_phone_numbers.txt The program reads the content of the file...
IN PYTHON Ask the user for a file name Open the requested file Split the contents of the file into words Iterate over each word Translate the word to Pig Latin Output the translated word to the screen How to Speak Pig Latin https://www.wikihow.com/Speak-Pig-Latin
Write a PYTHON program that asks the user for the name of the file. The program should write the contents of this input file to an output file. In the output file, each line should be preceded with a line number followed by a colon. The output file will have the same name as the input filename, preceded by “ln” (for linenumbers). Be sure to use Try/except to catch all exceptions. For example, when prompted, if the user specifies “sampleprogram.py”...
Write a MIPS Assembly language program to request a file name from the user, open the file, read the contents, and write it out to the console.
Write a MIPS Assembly language program to request a file name from the user, open the file, read the contents, and write it out to the console.