import random
while True:
length=int(input('Enter palindrome number length: '))
pnum=0
def palin_gen(length,pnum):
start=random.choice([x for x in range(9) if x!=pnum])
pnum=int(start)
if length%2!=0:
length=(length+1)/2-1
for a in range(int(length)):
radnt=random.randint(0,9)
start=(start*10)+radnt
for i in range(int(length-1),-1,-1):
start=start*10+int(str(start)[i])
else:
length=length/2-1
for a in range(int(length)):
radnt=random.randint(0,9)
start=(start*10)+radnt
radnt=random.randint(0,9)
start=(start*10)+radnt
for i in range(int(length),-1,-1):
start=start*10+int(str(start)[i])
return(start)
print(palin_gen(length,pnum))
choose=input('want another?[y/n]: ')
if choose.lower()=='y':
pass
else:
break
Post a Comment
Please leave a review