Answered step by step
Verified Expert Solution
Question
1 Approved Answer
using python answer all parts if possible a. 2. Edit or delete a user profile When the user chooses 2, the first thing that it
using python answer all parts if possible
a. 2. Edit or delete a user profile When the user chooses 2, the first thing that it should do is to check whether the user information is loaded in the program (i.e., check if the user information is passed to the function that generates recipe recommendations). If the user information is passed to the function (i.e., the user chose option 1 before choosing option 2), the program should show the user the following menu: Hello (user name) You can perform one of the following operations: 1) Delete your profile 2) Edit your profile If the user chooses 1, perform the following subtasks to delete a user profile: 1- Search for the user profile in the file userInformation.txt using the user name in read mode; once you find the user profile (i.e., the line that contains all the user information), pass it to a function that deletes the user information. 2- The function should create a temporary file called temp.txt in write mode and search the file userInformation.txt in read mode for the user that you want to delete (the user returned by the previous step). Write all the content of the file userInformation.txt in the file temp.txt so long as the user is not there, in other words, do not write (delete) the user. The end of this process should yield a file called temp.txt that does not include the user. 3- Use the os module to delete the file userInformation.txt, then use it to rename the file temp.txt as userInformation.txt. 4- Print to the user a message stating that was deleted successfully. 5. If the file user Information.txt contains just one user profile and you chose to delete this user, delete the file. 6- Make sure you also delete or clear the contents of the variable userInformation when you return to the main menu after successfully deleting the user profile. b. If the user chooses 2, perform the following subtasks to edit a user profile: Show the user the following menu, which displays the records that they can edit: Hello (user name) These are the fields that you can edit in your profile: 1) Name 2) Year of birth (or Date of Birth for bonus) 3) Gender 4) Height (m) 5) Weight (kg) 6) Activity level 7) Food allergies 1- If the user enters the number 1, perform the following: 1) Ask the user to enter their new user name. 3 2) Create a new record of user information that replaces the old name with the new name but keeps all the other fields the same (use string concatenation to do this). 3) Add the edit date to the end of the new user information record, this date corresponds to the date and time in which the user edited their profile. 4) Then, call a function that takes the old user information and the new user information. 5) The function should read the contents of the file userInformation.txt and write it to the file temp.txt, at the same time, search for the old user information, if found, replace it with the new user information and write it to the file temp.txt. 6) Just like what you did in deleting a file, delete the file userInformation.txt, then rename the file temp.txt to user Information.txt. 7) Make sure you also delete or clear the contents of the variable userInformation when you return to the main menu after successfully deleting the user profile. 2- If the user selects the number 2, perform the following: 1) Ask the user to enter their new year or date of birth, using this information, re-calculate the user age, the BMR, and the TEE. 2) Create a new record of user information that replaces the old year of birth or date of birth with the new information, replace the age with the new age, replace the BMR with a new BMR calculated from the new age, and replace the TEE with a new one from the new BMR. the other fields the same (use string concatenation to do this). 3) Repeat steps 3) to 7) from (a). 3- If the user selects the number 3, perform the following: 1) Ask the user to enter their new gender. Using this information, re-calculate the BMR and TEE. 2) Create a new record of user information that replaces the old gender with the new gender, replace the BMR with a new BMR calculated from the new gender, and replace the TEE with a new one from the new BMR. the other fields the same (use string concatenation to do this). 3) Repeat steps 3) to 7) from (a). If the user selects the number 4, perform the following: 1) Ask the user to enter the new height. Using this information, re-calculate the BMI, the BMI-range, the BMR, and the TEE. 2) Create a new record of user information that replaces the old height with the new height, replace the BMI with the new BMI calculated from the new height, replace the BMI range with a new range calculated from a new BMI, replace the BMR with a new BMR calculated from the new height, and replace the TEE with a new one from the new BMR. the other fields the same (use string concatenation to do this). 3) Repeat steps 3) to 7) from (a). 5. If the user selects the number 5, perform the following: 4) Ask the user to enter the new weight. Using this information, re-calculate the BMI, the BMI-range, the BMR, and the TEE. 5) Create a new record of user information that replaces the old weight with the new weight, replace the BMI with the new BMI calculated from the new weight, replace the BMI range with a new range calculated from a new BMI, replace the BMR with a new BMR calculated from the new weight, and replace the TEE with a new one from the new BMR. the other fields the same (use string concatenation to do this). 6) Repeat steps 3) to 7) from (a). 6- If the user selects the number 6, perform the following: 4- 4 1) Ask the user to enter the new activity level, just like the way you did when the user creates anew profile. Using this information, re-calculate the TEE. 2) Create a new record of user information that replaces the old activity level with the new one, and replace the TEE with the new TEE but keeps all the other fields the same (use string concatenation to do this). 3) Repeat steps 3) to 7) from (a). 7- If the user selects the number 7, perform the following: 4) Ask the user to enter the new list of allergies, just like the way you did when the user creates anew profile. 5) Create a new record of user information that replaces the old allergies with the new allergies but keeps all the other fields the same (use string concatenation to do this). 6) Repeat steps 3) to 7) from (a). a. 2. Edit or delete a user profile When the user chooses 2, the first thing that it should do is to check whether the user information is loaded in the program (i.e., check if the user information is passed to the function that generates recipe recommendations). If the user information is passed to the function (i.e., the user chose option 1 before choosing option 2), the program should show the user the following menu: Hello (user name) You can perform one of the following operations: 1) Delete your profile 2) Edit your profile If the user chooses 1, perform the following subtasks to delete a user profile: 1- Search for the user profile in the file userInformation.txt using the user name in read mode; once you find the user profile (i.e., the line that contains all the user information), pass it to a function that deletes the user information. 2- The function should create a temporary file called temp.txt in write mode and search the file userInformation.txt in read mode for the user that you want to delete (the user returned by the previous step). Write all the content of the file userInformation.txt in the file temp.txt so long as the user is not there, in other words, do not write (delete) the user. The end of this process should yield a file called temp.txt that does not include the user. 3- Use the os module to delete the file userInformation.txt, then use it to rename the file temp.txt as userInformation.txt. 4- Print to the user a message stating that was deleted successfully. 5. If the file user Information.txt contains just one user profile and you chose to delete this user, delete the file. 6- Make sure you also delete or clear the contents of the variable userInformation when you return to the main menu after successfully deleting the user profile. b. If the user chooses 2, perform the following subtasks to edit a user profile: Show the user the following menu, which displays the records that they can edit: Hello (user name) These are the fields that you can edit in your profile: 1) Name 2) Year of birth (or Date of Birth for bonus) 3) Gender 4) Height (m) 5) Weight (kg) 6) Activity level 7) Food allergies 1- If the user enters the number 1, perform the following: 1) Ask the user to enter their new user name. 3 2) Create a new record of user information that replaces the old name with the new name but keeps all the other fields the same (use string concatenation to do this). 3) Add the edit date to the end of the new user information record, this date corresponds to the date and time in which the user edited their profile. 4) Then, call a function that takes the old user information and the new user information. 5) The function should read the contents of the file userInformation.txt and write it to the file temp.txt, at the same time, search for the old user information, if found, replace it with the new user information and write it to the file temp.txt. 6) Just like what you did in deleting a file, delete the file userInformation.txt, then rename the file temp.txt to user Information.txt. 7) Make sure you also delete or clear the contents of the variable userInformation when you return to the main menu after successfully deleting the user profile. 2- If the user selects the number 2, perform the following: 1) Ask the user to enter their new year or date of birth, using this information, re-calculate the user age, the BMR, and the TEE. 2) Create a new record of user information that replaces the old year of birth or date of birth with the new information, replace the age with the new age, replace the BMR with a new BMR calculated from the new age, and replace the TEE with a new one from the new BMR. the other fields the same (use string concatenation to do this). 3) Repeat steps 3) to 7) from (a). 3- If the user selects the number 3, perform the following: 1) Ask the user to enter their new gender. Using this information, re-calculate the BMR and TEE. 2) Create a new record of user information that replaces the old gender with the new gender, replace the BMR with a new BMR calculated from the new gender, and replace the TEE with a new one from the new BMR. the other fields the same (use string concatenation to do this). 3) Repeat steps 3) to 7) from (a). If the user selects the number 4, perform the following: 1) Ask the user to enter the new height. Using this information, re-calculate the BMI, the BMI-range, the BMR, and the TEE. 2) Create a new record of user information that replaces the old height with the new height, replace the BMI with the new BMI calculated from the new height, replace the BMI range with a new range calculated from a new BMI, replace the BMR with a new BMR calculated from the new height, and replace the TEE with a new one from the new BMR. the other fields the same (use string concatenation to do this). 3) Repeat steps 3) to 7) from (a). 5. If the user selects the number 5, perform the following: 4) Ask the user to enter the new weight. Using this information, re-calculate the BMI, the BMI-range, the BMR, and the TEE. 5) Create a new record of user information that replaces the old weight with the new weight, replace the BMI with the new BMI calculated from the new weight, replace the BMI range with a new range calculated from a new BMI, replace the BMR with a new BMR calculated from the new weight, and replace the TEE with a new one from the new BMR. the other fields the same (use string concatenation to do this). 6) Repeat steps 3) to 7) from (a). 6- If the user selects the number 6, perform the following: 4- 4 1) Ask the user to enter the new activity level, just like the way you did when the user creates anew profile. Using this information, re-calculate the TEE. 2) Create a new record of user information that replaces the old activity level with the new one, and replace the TEE with the new TEE but keeps all the other fields the same (use string concatenation to do this). 3) Repeat steps 3) to 7) from (a). 7- If the user selects the number 7, perform the following: 4) Ask the user to enter the new list of allergies, just like the way you did when the user creates anew profile. 5) Create a new record of user information that replaces the old allergies with the new allergies but keeps all the other fields the same (use string concatenation to do this). 6) Repeat steps 3) to 7) from (a)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started