DevNet Associate DEVASC 200-901 Official Certification Guide by Adrian Iliesiu (z-lib.org)

(andrew) #1

Here is what the program output would look like with a
valid test.txt file in the script directory:


Click here to view code image


Which file would you like to open? :test
Sorry, test doesn't exist! Please try again.
Which file would you like to open? :test.txt
Test file with some text.
Two lines long.

Here is what the output would look like with three wrong
choices:


Click here to view code image


Which file would you like to open? :test
Sorry, test doesn't exist! Please try again.
Which file would you like to open? :test2
Sorry, test2 doesn't exist! Please try again.
Which file would you like to open? :test3
Sorry, test3 doesn't exist! Please try again.
Wrong filename 3 times.
Check name and Rerun.

There are quite a few other error-handling capabilities
available in Python, and if you want to try to make your
applications more user friendly, it would be worth your
time to explore them. The latest documentation can be
found at https://docs.python.org/3/tutorial/errors.html.
This documentation discusses custom errors and
provides more examples of types of errors you can use
with the previous sample code.


TEST-DRIVEN DEVELOPMENT


Test-driven development (TDD) is an interesting concept
that at first glance may seem completely backward. The
idea is that you build a test case first, before any software
has been created or modified. The goal is to streamline

Free download pdf