Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have made code to produce a NRIC checker but am not sure on how to apply for loop into this. The for loop is compulsory for my assignment.

What I have tried:

def main():

x = input("Enter your NRIC number here:")
if len(x) != 9:
print ("Please enter a legitimate NRIC.")
else:
first = int(x[1]) * int(2)
second =int(x[2]) * int(7)
third =int(x[3]) * int(6)
fourth= int(x[4]) * int(5)
fifth= int(x[5]) * int(4)
sixth= int(x[6]) * int(3)
seventh= int(x[7]) * int(2)
global y
y = (first + second + third + fourth + fifth + sixth + seventh)
h = int(y) % 11
b = 0
if h == 0:
b == "J"
elif h == 1:
b == "Z"
elif h == 2:
b == "I"
elif h == 3:
b == "H"
elif h == 4:
b == "G"
elif h == 5:
b == "F"
elif h == 6:
b == "E"
elif h == 7:
b == "D"
elif h == 8:
b == "C"
elif h == 9:
b == "B"
else:
b == "A"
if b == x[8]:
print ("Valid.")
else:
print("Invalid.")





main()
Posted
Updated 21-Jul-18 7:18am

1 solution

Something like:
Python
y = 0
mults = [2,7,6,5,4,3,2]
for i in range(0,6):
    val = int(x[i]) * mults[i]
    y += val
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900