123 def verify(number): # do not change this line! # write your code here so that it verifies the card number # be sure to indent your code! return True # modify this line as needed 8 9 10 input = "5000-0000-0000" # change this as you test your function output = verify(input) # invoke the method using a test input print(output) # prints the output of the function 11 12 # do not remove this line! The rules must be checked in this order, and if any of the rules are violated, the function should return the violated rule number, e.g. if the input is "4238-0679-9123", then the function should return 2, indicating that rule #2 was violated because although rule #1 was satisfied (the first digit is a 4), rule #2 was not, since the fourth digit (which is 8) is not one greater than the fifth (which is 0). If all rules are satisfied, then the function should return True. Note that the card number is not actually a number, but is a string of characters. In Python, you can generally use a string the same way you would use a list, e.g. accessing individual characters using their 0-based index. Hint: You will need to do this for checking all the rules. However, when you access a character using its 0-based index, Python will treat it as a character/letter and not a number, even if it's a digit, and you need to be careful about how you use it in mathematical operations. For instance, if you had the characters '1' and '2' and try to add them, Python would concatenate them and use them to form a longer string; in this case, you would get "12". However, if you try to subtract, multiply, divide, etc. then Python will give you an error. To convert a character/letter to a number, use the "int" function, e.g. "x = int('1')" will convert the character/letter '1' to the number 1 so that you can use it in mathematical operations. Hint: you will need this for rules 2-4. 567

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Don't copy the code

Description
Credit card companies and banks use built-in security measures when creating the
account numbers on credit cards to make sure the card numbers follow certain rules
(you didn't think they were random, did you?). This means that there are only certain
valid credit card numbers, and validity can quickly be detected by using an algorithm
that may involve adding up parts of the numbers or performing other checks.
In this activity, you will implement a function that determines whether or not a card
number is valid, according to some simple algorithms. Note that these algorithms are
purely made-up; don't try to use them to create fake credit card numbers! :-)
We will assume that the credit card number is a string consisting of 14 characters and is
in the format #### #### ####, including the dashes, where '#' represents a digit
between 0-9, so that there are 12 digits overall. We will revisit this assumption in the an
optional later activity.
In the space below, implement a function called "verify" that takes a single parameter
called "number" and then checks the following rules:
1. The first digit must be a 4.
2. The fourth digit must be one greater than the fifth digit; keep in mind that these
are separated by a dash since the format is ####-####-
3. The sum of all digits must be evenly divisible by 4.
4. If you treat the first two digits as a two-digit number, and the seventh and eighth
digits as a two-digit number, their sum must be 100.
Transcribed Image Text:Description Credit card companies and banks use built-in security measures when creating the account numbers on credit cards to make sure the card numbers follow certain rules (you didn't think they were random, did you?). This means that there are only certain valid credit card numbers, and validity can quickly be detected by using an algorithm that may involve adding up parts of the numbers or performing other checks. In this activity, you will implement a function that determines whether or not a card number is valid, according to some simple algorithms. Note that these algorithms are purely made-up; don't try to use them to create fake credit card numbers! :-) We will assume that the credit card number is a string consisting of 14 characters and is in the format #### #### ####, including the dashes, where '#' represents a digit between 0-9, so that there are 12 digits overall. We will revisit this assumption in the an optional later activity. In the space below, implement a function called "verify" that takes a single parameter called "number" and then checks the following rules: 1. The first digit must be a 4. 2. The fourth digit must be one greater than the fifth digit; keep in mind that these are separated by a dash since the format is ####-####- 3. The sum of all digits must be evenly divisible by 4. 4. If you treat the first two digits as a two-digit number, and the seventh and eighth digits as a two-digit number, their sum must be 100.
12345678
def verify(number)
: # do not change this line!
#write your code here so that it verifies the card number
# be sure to indent your code!
return True # modify this line as needed
9
10
input = "5000-0000-0000" # change this as you test your function
output = verify(input) # invoke the method using a test input
print(output) # prints the output of the function
11
12
# do not remove this line!
The rules must be checked in this order, and if any of the rules are violated, the function
should return the violated rule number, e.g. if the input is "4238-0679-9123", then the
function should return 2, indicating that rule #2 was violated because although rule #1
was satisfied (the first digit is a 4), rule #2 was not, since the fourth digit (which is 8) is
not one greater than the fifth (which is 0). If all rules are satisfied, then the function
should return True.
Note that the card number is not actually a number, but is a string of characters. In
Python, you can generally use a string the same way you would use a list, e.g.
accessing individual characters using their 0-based index. Hint: You will need to do this
for checking all the rules.
However, when you access a character using its 0-based index, Python will treat it as a
character/letter and not a number, even if it's a digit, and you need to be careful about
how you use it in mathematical operations. For instance, if you had the characters '1'
and '2' and try to add them, Python would concatenate them and use them to form a
longer string; in this case, you would get "12". However, if you try to subtract, multiply,
divide, etc. then Python will give you an error.
To convert a character/letter to a number, use the "int" function, e.g. "x = int('1')" will
convert the character/letter '1' to the number 1 so that you can use it in mathematical
operations. Hint: you will need this for rules 2-4.
Transcribed Image Text:12345678 def verify(number) : # do not change this line! #write your code here so that it verifies the card number # be sure to indent your code! return True # modify this line as needed 9 10 input = "5000-0000-0000" # change this as you test your function output = verify(input) # invoke the method using a test input print(output) # prints the output of the function 11 12 # do not remove this line! The rules must be checked in this order, and if any of the rules are violated, the function should return the violated rule number, e.g. if the input is "4238-0679-9123", then the function should return 2, indicating that rule #2 was violated because although rule #1 was satisfied (the first digit is a 4), rule #2 was not, since the fourth digit (which is 8) is not one greater than the fifth (which is 0). If all rules are satisfied, then the function should return True. Note that the card number is not actually a number, but is a string of characters. In Python, you can generally use a string the same way you would use a list, e.g. accessing individual characters using their 0-based index. Hint: You will need to do this for checking all the rules. However, when you access a character using its 0-based index, Python will treat it as a character/letter and not a number, even if it's a digit, and you need to be careful about how you use it in mathematical operations. For instance, if you had the characters '1' and '2' and try to add them, Python would concatenate them and use them to form a longer string; in this case, you would get "12". However, if you try to subtract, multiply, divide, etc. then Python will give you an error. To convert a character/letter to a number, use the "int" function, e.g. "x = int('1')" will convert the character/letter '1' to the number 1 so that you can use it in mathematical operations. Hint: you will need this for rules 2-4.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY