def extractDigits(num):
d4 = num%10
d3 = (num//10)%10
d2 = (num//100)%10
d1 = (num//1000)%10
return (d1,d2,d3,d4)
def noRepeatingDigits(num):
(d1,d2,d3,d4) = extractDigits(num)
return not (d1 == d2 or d1 == d3 or d1 == d4 or d2 == d3 or d2 == d4 or d3 == d4)
# bulls and cows program. read user input 4-digit number with no repeats
# invalid input: (1) enter non-digits (2) number of digits is not 4 (3) no repeats
def readUserInput(gnum):
s = input("Enter guess number "+str(gnum)+": ")
while not s.isnumeric():
print("Please enter only digits")
s = input("Enter guess number "+str(gnum)+": ")
num = int(s)
while not noRepeatingDigits(num) or num < 1000 or num > 9999:
print("Please provide 4-digit number with no repeats")
s = input("Enter guess number "+str(gnum)+": ")
while not s.isnumeric():
print("Please enter only digits")
s = input("Enter guess number "+str(gnum)+": ")
num = int(s)
return num
readUserInput(5)
s = "1234"
t = "1w34"
print(int(s))
print(int(t))
s.isnumeric()
t.isnumeric()
u = "ab1d"
u.isalpha()
u.isalnum()
int("231")