I am trying to convert my credit solution from C to python, but for some reason it is not working. Attached is my code and the problems
from cs50 import get_int
card, a, m, v = False, False, False, False
sum = 0
num = get_int("Number: ")
numcopy = num
i = 0
for j in range(num):
if (i % 2) == 0:
digit = num % 10
sum += digit
else:
digit = num % 10
digit *= 2
while digit > 1:
digitmultiply = intdigit % 10
sum += digitmultiply
digit /= 10
num /= 10
i += 1
if (sum % 10) == 0:
card = True
while numcopy > 100:
numcopy /= 10
if numcopy in [34, 37]:
a = True
if numcopy in [51, 52, 53, 54, 55]:
m = True
if (numcopy / 10) == 4:
if i == 13 or i == 16:
v = True
if card and v:
print("VISA")
elif card and m and i == 16:
print("MASTERCARD")
elif card and a and i == 15:
print("AMEX")
else:
print("INVALID")
My code keeps getting stuck in the for loop. I have tried making print lines under the first if (i % 2) == 0: loop, and it keeps looping and giving me the same value, a float (Depending on the input) like 67.97306575341835 and my digit value is consistently 0 while the program is still stuck in the loop.
I am unable to figure out what is wrong with my program, and would greatly appreciate any input or advise. Thank you everyone!