0

There's some French in the code but don't worry about it, the only thing I want to do here is add something that will prevent me from entering a string under 4 in ch1 and at least 1 character in ch2. this code works for what I'm doing.

ch1 = input("Entre the first chain:")
ch2 = input('Enter the second chain:')
resultat = 0
sub_len = len(ch2)


for i in range(len(ch1)):
    if ch1[i:i+sub_len] == ch2:
        resultat += 1

print('Chaîne 1 saisie: {}'.format(ch1))
print('Chaîne 2 saisie: {}'.format(ch2))
print('Réponse: La chaîne 2 se retrouve {} fois dans la châine 1.'.format(resultat))
depperm
  • 10,606
  • 4
  • 43
  • 67
Oxynor
  • 41
  • 6

1 Answers1

0

You have to test yourself for the length of the input string and repeat the input if it is not valid, in a loop.

One of the ways to do it:

while True:
    ch1 = input("Entre the first chain: (minimum 4 chars)")
    if len(ch1) >= 4:
        break

while True:
    ch2 = input('Enter the second chain (minimum 1 char):')
    if len(ch2) >= 1:
        break
nosklo
  • 217,122
  • 57
  • 293
  • 297