Question: USING PYTHON PRAOGRAMMING AND WHILE LOOPS (DO NOT USE FOR LOOPS) Write a program that asks the user to enter a P IN number and
USING PYTHON PRAOGRAMMING AND WHILE LOOPS (DO NOT USE FOR LOOPS)
Write a program that asks the user to enter a
P
IN number
and the type of
account it is for,
and then checks
t
he PIN
for a few different requirements
before approving it as secure
and repeating the final selection to the user
.
The program follows
t
hese
rules for
P
IN numbers
:
1.
If the
PIN is for a
checking
or
debit
account, it must
a.
Be four digits
long
i.
T
his means
no leading zeros (
0678 is not valid, nor is 0003)
b.
Not
end in a
0
(zero)
2.
If the PIN is for a
savings
account, it must
a.
Be three digits
long
i.
T
his means
no leading zeros (
0
35
is not valid, nor is 00
9
)
b.
Not
be the same number repeated (333 is not valid, nor is 888, etc.)
i.
(Think carefully about how to check this one
it
s not as
difficult as it may seem!)
The program can assume that the user will enter
c
(for checking),
d
(for
debit), or
s
(for savi
ngs) as their account type.
The program must re
-
prompt the user until they provide a
PIN
/account type
combination
that satisfies all of the conditions above
.
It must also tell the
user each of the conditions they failed, and how to fix it.
If there is more than one thing wrong (
e.g.
,
not four digits, and ends in
a zero
for a
checkin
g
account)
,
the program must print out bo
th of the things that
are wrong
/
how to fix them.
For this part of the homework, you
must
have
a
n in
-
line
comment
at the top
of
each
of your programs individual
if
,
elif
, and
else
sta
tements,
explaining what is being checked
by that conditional.
(HINT: Think carefully about what your conditionals should look like
. If
necessary, draw a truth table to help figure out what different inputs will do.
Using a Boolean flag will also likel
y make this easier.)
SAMPLE OUTPUT
Please enter a PIN:
6
Please enter the account type (c, d, or s):
c
The PIN 6 is too short for a checking account.
Please enter a PIN:
60
Please enter the account type (c, d, or s):
d
The PIN 60 is too short for a
d
e
bit
account.
The PIN 60 ends in a zero.
Please enter a PIN:
600
Please enter the account type (c, d, or s
):
c
The PIN 600 is too short for a checking account.
The PIN 600 ends in a zero.
Please enter a PIN:
6000
Please enter the account type (c, d, or s):
c
The PIN 6000 ends in a zero.
Please enter a PIN:
6006
Please enter the account type (c, d, or s):
c
Tha
nk you for picking the pin 6006 for your account.
bash
-
4.1$ python hw4_part5.py
Please enter a PIN:
555
Please enter the account type (c, d, or s):
s
The PIN 555 is three numbers repeated.
Please enter a PIN:
55
Please enter the account type (c, d, or s):
s
The PIN 55 is too short for a savings account.
Please enter a PIN:
515
Please enter the account type (c, d, or s):
s
Thank you for picking the pin 515 for your account.
bash
-
4.1$ python hw4_part5.py
Please enter a PIN:
6789
Please enter the account type
(c, d, or s):
s
The PIN 6789 is too long for a savings account.
Please enter a PIN:
6789
Please enter the account type (c, d, or s):
d
Thank you for picking the pin 6789 for your account.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
