Hi everyone
, I'm Santiago,
I have a small problem that I cannot detect in my code
.
It is a homework from the university
.
I have all the code written and it works "fine"
.
As you can see, the final result is correct, but until the program reaches it makes many prints that I do not understand why he does them
.
If someone could help me I would appreciate it.
I leave the homework statement and the code I have so that you can check and see where it fails.
Thanks a lot!
The exercise is as follows:
Write a python program, which reads two strings S1 and S2. You can consider the input strings are not empty (contain at least one character). The strings are then converted to the linked lists L1 and L2 – the nodes of linked lists contain individual characters of the original strings. The program then finds (and prints) the number of occurrences of the list L2 in the list L1.
Examples:
Input: alphabetical
al
Output: 2
The input strings S1 is “alphabetical” and S2 is “al”. The linked lists L1 and L2 are therefore.
Input: alphabetical
ax
Output: 0
Thank you very much for your help, and I am very sorry for the problems and for not understanding the linked list.
The code I have:

I have a small problem that I cannot detect in my code

It is a homework from the university

I have all the code written and it works "fine"

As you can see, the final result is correct, but until the program reaches it makes many prints that I do not understand why he does them

If someone could help me I would appreciate it.
I leave the homework statement and the code I have so that you can check and see where it fails.
Thanks a lot!


The exercise is as follows:
Write a python program, which reads two strings S1 and S2. You can consider the input strings are not empty (contain at least one character). The strings are then converted to the linked lists L1 and L2 – the nodes of linked lists contain individual characters of the original strings. The program then finds (and prints) the number of occurrences of the list L2 in the list L1.
Examples:
Input: alphabetical
al
Output: 2
The input strings S1 is “alphabetical” and S2 is “al”. The linked lists L1 and L2 are therefore.
Input: alphabetical
ax
Output: 0
Thank you very much for your help, and I am very sorry for the problems and for not understanding the linked list.
The code I have:
# node implementation s = input('enter the full string: ') s_sub =input('enter the character to match: ') class node: def __init__(self, x): self.value = x self.next = None def moving_onto(L): while L is not None: print(L.value, end = " ") L = L.next print() count = 0 for i in range(len(s)): L = node(s_sub) end = L if s[i:i+len(s_sub)] == s_sub: count +=1 end.next = node(s_sub) end = end.next print("no of sub_string: ", count)