0

CODE COACH: MATCHING PASSWORDS (Python Core 33.2)

In Code Coach 33.2 in Python Core, we are presented with an exercice to make a lowly password checker. This is the (working) solution I found: password = input() repeat = input() def validate(text1, text2): #your code goes here if text1 == text2: print("Correct") else: print("Wrong") validate(password, repeat) My initial solution, which didn't work, wasn't much different, but included "" around text1 and text2 when checking their values. password = input() repeat = input() def validate(text1, text2): #your code goes here if "text1" == "text2": print("Correct") else: print("Wrong") validate(password, repeat) In this case, it worked for alphanumeric strings, such as "John874" but didn't for purely numeric strings, such as "14386562". I thought it was odd, considering "password" and "repeat", being "input()" without an "int()" should be treated as strings even in the case they were indeed numbers. That's okay, I thought... [1/2]

18th Sep 2022, 9:16 PM
Alea EVANGELII
Alea EVANGELII - avatar
13 Respuestas
0
That's OK, I thought. I'll simply make sure they're treated as strings, twice (which they should already be, as non-converted products of an input() function), and all should work out fine. And so, my second try was this: password = str(input()) repeat = str(input()) def validate(text1, text2): #your code goes here if "text1" == "text2": print("Correct") else: print("Wrong") validate(str(password), str(repeat)) Same problem arose: Output posted "Correct" when faced with matching alphanumeric strings such as "John874", but kept posting "Wrong" when presented with matching purely numeric strings such as "14777885". In this latter code, I should be quite sure numeric strings are treated as strings. So the "" around text1 and text2 should hold no relevance whether the string is alphanumeric or numeric: at the end of the day, it's still a unicode characters string. What am I missing, here? [2/2]
18th Sep 2022, 9:25 PM
Alea EVANGELII
Alea EVANGELII - avatar
+ 1
Do you understand that you are comparing words, not the values ​​of the function arguments? 🤔: def validate(text1, text2): #words👇 👆arguments if "text1" == "text2":
18th Sep 2022, 10:50 PM
Solo
Solo - avatar
+ 1
You're carrying some nonsense. Open your eyes, turn on your brain, and remove the quotation marks in the condition.
19th Sep 2022, 10:08 AM
Solo
Solo - avatar
+ 1
My answer: — "You're carrying some nonsense. Open your eyes, turn on your brain, and remove the quotation marks in the condition."; Refers to your answer to your own question, which you had the audacity to mark as the best answer. I'm talking to you the way you deserve it. Judging by your statements, you are not a stupid person and you understand everything perfectly, which means you are deliberately misleading students. Your code will always print "Incorrect" whatever data you enter, as you don't validate it. Why should SoloLearn users waste their time on you? I came here to study and communicate with like-minded people, at the same time helping those who want to learn, but you apparently do not belong to them, to master the material covered. Do you miss the attention of the people around you?
19th Sep 2022, 2:28 PM
Solo
Solo - avatar
0
You don't need classes for 33.2, but a function.
18th Sep 2022, 9:19 PM
Paul
Paul - avatar
0
Solo I thought I was comparing both strings. I don't know what a "word" is, in Python. I know strings, which all words I can think of are. Strings are also single characters, sentences, or numbers (when considered merely for the UNICODE value of their digits, and not as a unit of numeric meaning). That's my understanding of strings: a class analogous to lists, devoted to the presentation without commas of single Unicode characters appended one after the next. Meaning, at least as far as I understand it, the string is never made of words, but of a "list" of single-character unicode values. The string "I suck at Python" is no more made from the words "I" "suck" "at" and "Python" than it is made from the substrings "I su", "ck at Py" and "thon". So I fail to see how the strings "John874" and "John874" could be compared and deemed identical by the interpreter, while the strings "874" and "874" could not. I mean, when the interpreter deems "John874"="John874", how could it not feel "874"(string)="874"(string)?
19th Sep 2022, 8:32 AM
Alea EVANGELII
Alea EVANGELII - avatar
0
Solo "You're carrying some nonsense." => I'm not "carrying" anything, I'm asking a simple question about classes. As to my failure to understand everything, it is quite obvious: my initial code didn't work. Hence the question I'm asking. "Open your eyes, turn on your brain" => Random insults, without providing any actual answer will not help a beginner. I do realize you must not be very competent, as a teacher or as a coder, which can lead to frustration. I'm fine with it: I'm even less competent than you in these departments and am quite frustrated with myself. But hey, it's not my fault if you're incompetent too... Why take it out on me? "and remove the quotation marks in the condition." => I already KNOW removing the quotations around text1 and text2 works: it's in the original post. I'm not asking if I should remove these quotations for the code to work. That point was already established without your "help". What I'm asking is: Why does the code work with quote marks if the string is alphanumeric?
19th Sep 2022, 10:43 AM
Alea EVANGELII
Alea EVANGELII - avatar
0
Solo And why doesn't it work if the string is purely numeric? So, maybe you're actually worth your salt as a coder and teacher, and you can in fact understand and answer the question. Which I would greatly appreciate. And maybe you have nothing to provide beyond trite third-grader insults such as "Turn your brain on, ROFLMAO", and Captain Obvious bullsh*t. In which case, you might as well fly to someone else's rescue: I should survive the loss of your grand input. Cheers, mate.
19th Sep 2022, 10:46 AM
Alea EVANGELII
Alea EVANGELII - avatar
0
Judging by your last statement, you are not only ignorant, but also outright boorish. Don't be surprised if you get banned after a while. Or do you think that since you bought the pro version, you can't be blocked?
19th Sep 2022, 2:53 PM
Solo
Solo - avatar
0
"My answer: Refers to your answer to your own question, which you had the audacity to mark as the best answer." => See the [1/2] at the end of my question? That means the question isn't finished, because I'm limited in characters. See the [2/2] at the end of my "answer to my own question]"? That means it's the end of my question. Hence why I marked it as best answer until I got a real answer (obviously not from you): it was the only way to "pin" it to the rest of the question. That is also the reason why the last sentence of my question, is the same as the first sentence of my "best answer". To suggest the incredible notion of continuity to simpletons such as yourself and allow them to at least understand the question before they shower me with their valued knowledge. To no avail, it seems... Oh well. Thanks anyway.
19th Sep 2022, 4:10 PM
Alea EVANGELII
Alea EVANGELII - avatar
0
"Judging by your statements, you are not a stupid person and you understand everything perfectly, which means you are deliberately misleading students." => That little paranoia of yours sounds like a compliment. The truth is I have never programmed before, and I started a week ago with Python and this app (and PythonX). "Your code will always print "Incorrect" whatever data you enter, as you don't validate it." => But it does work, with alphanumeric strings. Try it with "John874" as text1 and text2, and "text1"=="text2" does check fine. Output is "Correct". Do the same with "874", and output is "Wrong". That is the discrepancy I'm trying to understand. If indeed my code always printed "Incorrect", I wouldn't be asking the question: "Why does it work with alphanumeric strings and not purely numeric strings?".
19th Sep 2022, 4:19 PM
Alea EVANGELII
Alea EVANGELII - avatar
0
When you use "text1" == "text2" what you are really comparing are the strings (text1 and text2) that's the reason your code wasn't working.
20th Sep 2022, 9:20 PM
Doug Left
Doug Left - avatar
0
Doug Left I understand that. The question being, how come the code worked when comparing the string "John872" as text1 and text2, while it failed when comparing "872" as text1 and text2?
20th Sep 2022, 11:14 PM
Alea EVANGELII
Alea EVANGELII - avatar