Write a program that asks the user to answer some questions. First, you should ask the user if they want to load answers from a previously saved file. If they respond yes you should look for the file name of your choosing in the path of your choosing and try to load that. If no file was previously saved or they answered no, the user must answer 8 questions of your choosing. They can be simple (i.e. What is your favorite color?) or they can be difficult (i.e. When the zombie apocalypse comes would you sacrifice your friend for your own survival if need be?). In your file you should save the questions and the answers on the same line so it will look like this: What is your favorite color? Blue How old are you? 25 By doing this we can read in an entire line and simply separate the question based on the location of the question mark, anything before it and including it is the question and anything after it is the answer. If the user wants to load previous questions and the file exists you should print out the question on one line and the answer on another

In order to develop a program that asks the user to answer questions and provides the functionality to load answers from a previously saved file, we need to follow the given specifications.

Firstly, the program should prompt the user to indicate whether they want to load answers from a previously saved file. To achieve this, we will use the input() function to obtain the user’s response. The user can enter either “yes” or “no” as their answer.

“`
load_from_file = input(“Do you want to load answers from a previously saved file? (yes/no): “)
“`

Next, we need to handle the scenarios based on the user’s response. If the user selects “yes”, the program should attempt to load the answers from a file. The file name and path can be predetermined within the program. We will use the try-except block to catch any errors that may occur during the file loading process.

“`
if load_from_file.lower() == “yes”:
try:
file_name = “answers.txt” # Name of the file to load from
file_path = “/path/to/file” # Path to the file to load from
# Load answers from file logic goes here
except FileNotFoundError:
print(“No file was found. Please provide answers to the questions.”)
“`

On the other hand, if the user selects “no” or no file was found, the program should prompt the user to answer a predetermined set of questions. We can implement this by using a for loop to iterate over the questions and collect the user’s responses using input().

“`
else:
questions = [“What is your favorite color?”, “How old are you?”, “…” ] # List of predetermined questions

for question in questions:
answer = input(question + ” “)
# Save answers to file logic goes here
“`

After obtaining the answers from the user, we need to save them to a file following the required format. To accomplish this, we will open a file in write mode using the open() function and use the write() method to store each question and its corresponding answer on a separate line.

“`
filename = “answers.txt” # Name of the file to save the answers

with open(filename, “w”) as file:
for question, answer in zip(questions, answers):
file.write(question + ” ” + answer + “n”)
“`

By following these steps, our program will successfully handle the user’s request to load answers from a previously saved file or prompt the user to answer a set of predetermined questions and save the answers to a file.

Need your ASSIGNMENT done? Use our paper writing service to score better and meet your deadline.


Click Here to Make an Order Click Here to Hire a Writer