location=input("Where did you see the birds? ")
print()
flock_size=int(input("Approximately, how many did you see? "))
#
###### Mutate Sighted Birds' Information ####
#
bird_sighting.set_sight_location(location)
bird_sighting.set_sight_date(datetime.date.today())
if species == '1': #CHANGE
bird_sighting.set_bird_species('barn swallow')
else:
bird_sighting.set_bird_species('SA cliff swallow')
bird_sighting.set_flock_size(flock_size)
#
(Notice that the mutators, such as .set_sight_date, are now all from the
bird_sighting subclass.)
- For the fourth change, in the section Display Sighting Data, delete the following
Python statements:
Click here to view code image
print("Sighting on \t", datetime.date.today())
if species == '1':
print("Species: \t European/Barn Swallow")
print("Flock Size: \t", barn_swallow.get_flock_size())
print("Sex: \t\t", barn_swallow.get_sex())
else:
print("Species: \t South Africa Cliff Swallow")
print("Flock Size: \t", sa_cliff_swallow.get_flock_size())
print("Sex: \t\t", sa_cliff_swallow.get_sex())
- In place of what you just deleted, add the following:
Click here to view code image
print("Sighting Date: \t", bird_sighting.get_sight_date())
print("Location: \t", bird_sighting.get_sight_location())
if species == '1':
print("Species: \t European/Barn Swallow")
else:
print("Species: \t South Africa Cliff Swallow")
print("Flock Size: \t", bird_sighting.get_flock_size())
(Notice that the accessors, such as .get_flock_size, are now all from the
bird_sighting subclass.)
- Review the four major changes you just made to script1503.py to ensure that there are
no typos and that the indentation is correct. - Write out the information from the text editor to the script by pressing Ctrl+O. The script file
name shows along with the prompt File name to write. Press Enter to write out the
contents to the script1503.py script. - Exit the nano text editor by pressing Ctrl+X. All your work is about to pay off!
- To test your modifications to the script, at the command-line prompt, type python3
/home/pi/py3prog/script1503.py and press Enter. Answer the script questions
as you please. If there are no problems with your script or object definition file, the output
will look similar to Listing 15.10.