Isaac Rivera Isaac Rivera - 1 year ago 97
Python Question

How to check if two consecutive digits are the same in python

I found this practice today:

Detect whether a check number is valid or not. The check number must have 10 digits, can not have 2 or more zeros followed, nor three or more digits other than zero followed

I've able to complete the first part with this code:

num_chk=input('Enter chk number: ')

if (len(num_chk) == 10):
print('valid')
else:
print('not valid')


any thoughts on how to create the logic to check if the check number has 2 consecutive 0.

thanks

Answer Source

Let's say your check number is the variable check_number and it is 12300.

check_number = 12300

convert it to a string:

str_check_num = str(check_number)
# str_check_num now equals "12300" a a string
has_00 = "00" in str_check_num
# Returns True if "00" is in str_check_num. in this case it is.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download