Question: Pet Name and Age Script Please refer to the PowerPoint slide for this week as that contains pet info review code that will be valuable
Pet Name and Age Script
Please refer to the PowerPoint slide for this week as that contains pet info review code that will be valuable for allowing students some practice when it comes to creating dictionaries and working with file modes.
Students will be creating a script that contains pet information and the age of the pet. The script will create a dictionary and then reference a separate file called petinfo.txt
The script must be able to allow the user to add a new pet and their age, delete a record, print oldest pet.
Rubric:
Make sure you upload screen captures of the code and the output
Make sure you add a new pet and their age be creative on the name show screen capture
Make sure you delete a pet from original list show screen capture
Make sure you print the name of the oldest pet show screen capture let's add some pet names and ages to the petinfo.txt file first! let's add some pet names and ages to the petinfo.txt file first! Now let's create our script
def readdata:
data
inFile openpetinfotxtr
for line in inFile:
fields line.split
name fields
age fields
dataname intage
inFile.close
return data
data readdata
We'll use a loop to provide a menu
while True:
printWelcome pleaes review pet info"
print Add or update a pet name record"
print Delete a pet name record"
print Print the name of the oldest pet"
print Exit"
ans intinputEnter Your Choice:
if ans :
name inputEnter Name:
age intinputEnter Age:
dataname age
elif ans :
name inputEnter name:
if name in dataz:
del dataname
else:
printname not in dictionary" Create remaining elif statements and also an else statement
elif ans :
highest
for key in data:
if datakey highest:
highest datakey
key key
printThe oldest pet on file is: keystrhighest
else:
break
Final Step, run your script and test every menu option to ensure the script works correctly.
Welcome, pleaes review pet info
Add or update a pet name record
Delete a pet name record
Print the name of the oldest pet
Exit
Enter Your Choice:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
