educative.io

Learn Python from scratch Python Exam 1

So the last question I dont understand can someone help me? Here is the question :

In this coding exercise, you are asked to write the body of a function called detect_pattern that returns true or false
depending upon whether two strings have the same pattern of characters.
**More precisely, two strings have the same pattern if they are of the same length and if two characters **
in the first string are equal if and only if the characters in the corresponding positions in the second string are also equal.

“A” “A” True
“X” “Y” True
“AB” “XY” True
“ABA” “XYZ” False
“AAASSSIIII” “GGGDDDFFFH” False

I know how for the same lenght and the loop part but for the 2 characters I don’t know and they don’t reffer you to an exemple so its complicated. Thanks

Hi @qwiwqi, please share the lesson link. Thanks!

Learn Python 3 from Scratch - Free Interactive Course (educative.io)

In the exam 1 it’s the last one

Hi @qwiwqi, Thanks for sharing the lesson link. Your query will be answered shortly.

Hi @qwiwqi!!
This statement describes a pattern between two strings. It’s saying that for two strings to have the same pattern, the characters in the first string must be equal if and only if the characters in the corresponding positions in the second string are also equal.
In the example “ab” and “xy” do have the same pattern, despite “a” not being equal to “x” and “b” not being equal to “y”.

When comparing the characters in the two strings, it’s important to consider their position in the string. The statement “two characters in the first string are equal if and only if the characters in the corresponding positions in the second string are also equal” means that the characters must match up in the same position in both strings.

In the case of “ab” and “xy”, the first character in the first string (“a”) corresponds to the first character in the second string (“x”), and the second character in the first string (“b”) corresponds to the second character in the second string (“y”). So the two strings have the same pattern.
I hope it helps.Happy Learning :blush:

1 Like

Yes thanks, I was so mad becasue I didn’t understand it. My primary language is not english so I kinda missunderstand it. It’s funny because I asked ChatGPT to explain how I could do this. He showed me the code then explain how to get the position of ex. A in the first string to compare with the second one. Thanks for the explications.

1 Like