I am relatively new to python but am currently stuck on this program. My goal is too validate a credit card number by testing the length and the first number
I have figured out the length requirement but as you can see in the code below I use the == sign to check if the first digit is equal to either 4, 5 ,6 or 38 but whatever number I put in it comes out as valid? Keep in mind I am using Pycharm
Any help or recommendations would be appreciated
(input)
“”“‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’’
This function will validate a credit card number
“””
#This function checks the length of the card number
def main():
number = str(input("Enter your credit card number (must be between 13 and 16 digits): "))
# This function checks the length of the card number
def isValid(number):
max = 16
min = 13
# check if the card number length is to long
if len(number) > max:
print("The number length is Invaid")
# check if the card number length is too short
elif len(number) < min:
print("The number length is Invaid")
# if length is correct check if it has correct first digit
else:
print("The number length is Valid")
print("Number is", number)
number_str = str(number)
first_digit = number_str[0]
if first_digit == 4 or 5 or 6:
print("The First Card number is Valid")
elif number_str[0] == 3 and number_str[1] == 8:
print("The First Card number is Valid")
else:
print("First Card Number not Valid")
quit()
isValid(number)
main()
‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’’
(output)
Enter your credit card number (must be between 13 and 16 digits): 20000000000000
The number length is Valid
Number is 20000000000000
The First Card number is Valid