ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Though simple, but was interested in the site that states to build up a project in steps.
The very first project is stuck at: https://www.freecodecamp.org/learn/s...cipher/step-17.
The original answer, as well as the modified one, don't help; as shown in the two attachments attached herewith.
The further steps are blocked by the unknown error, so needed help.
--------
Edit : Sorry, am unable to add images (screenshots), and this is continuing.
--------
Edit 2: Same error of 'Security token missing', on attempting from smartphone, too.
Please quote (as text) all of these:
- what do you wish to accomplish
- your program (complete and minimal)
- the error message or symptom you got
Note: attaching screenshot images is very insulting, don't do that
1. - what do you wish to accomplish
I intend to complete a particular step of the project, that is building up in an incremental manner the very first project. And am stuck at the 17th step.
The code is:
Code:
text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
index = alphabet.find(text[0])
print(index)
print(alphabet.find(text[0].lower()))
#text1 = text[0].lower()
#print(alphabet.find(text1))
# The last two lines, even when uncommented bring no change to the status quo.
Step 17
Remove the last print() call. Then, instead of text[0], pass text[0].lower() to .find() and see the output.
3. - the error message or symptom you got
The error it gives is:
Code:
Sorry, your code does not pass. You're getting there.
You should update your alphabet.find(text[0]) call to use text[0].lower() as the argument. Pay attention to place the method call at the beginning of the line.
P.S.: For the last line, hope with time would understand it.
Your program prints -1 and then 7. Is that what you wanted, or something else?
Code:
$ python3 ajiten17.py
-1
7
Guess you forgot to comment out two lines from the earlier step:
Code:
text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
# index = alphabet.find(text[0])
# print(index)
print(alphabet.find(text[0].lower()))
Thanks, but the 'index' variable need be retained, as it was there in some earlier step; and might be the problem wants to reuse it in some further step(S). Else, it gives error on the deletion of that variable too.
Code:
text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
index = alphabet.find(text[0].lower())
print(index)
So the issue is you have not followed the instructions correctly.
Original code:
Code:
text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
index = alphabet.find(text[0])
print(index)
print(text.lower())
Which returns the following:
Code:
>>> -1
>>> hello world
-1 is returned as text[0] is "H" which is not in the varaible alphabet and is assigned to variable index
hello world is returned in final print which is displaying value of "text" variable in lower case
What you were requested to do:
Quote:
Step 17
Remove the last print() call. Then, instead of text[0], pass text[0].lower() to .find() and see the output.
So remove / comment out last print()
Code:
text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
index = alphabet.find(text[0])
print(index)
#print(text.lower())
Second change is to locate the variable "text[0]" (note it does not say "text") and replace with text[0].lower() in .find()
Code:
text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
index = alphabet.find(text[0].lower())
print(index)
#print(text.lower())
With these 2 changes made the output is now 7 as text[0].lower() is a lower case "h" which is at position 7 in the alphabet variable
Though simple, but was interested in the site that states to build up a project in steps.
The very first project is stuck at: https://www.freecodecamp.org/learn/s...cipher/step-17.
The original answer, as well as the modified one, don't help; as shown in the two attachments attached herewith.
The further steps are blocked by the unknown error, so needed help.
--------
Edit : Sorry, am unable to add images (screenshots), and this is continuing.
--------
Edit 2: Same error of 'Security token missing', on attempting from smartphone, too.
As you have been asked several times before, please post your code examples inline here at LQ and refrain from posting off-site links and images as your primary example code.
* Posting your code inline here prevents loss of context over time due to disappearing images and linked resources, thus preserving the full context of the question and its solution in one place. This preserves the value of the information found here at LQ and respects the efforts of others who take time to provide help, both for yourself and for all future visitors.
* Failure to post your code examples as text, inline and properly formatted using [CODE]...[/CODE] tags may be most convenient for you, but is disrespectful of the time taken by others to consider your question and provide replies. It requires extra effort on their part just to understand the question, then to either follow links off-site or type the examples themselves in order to reproduce the error conditions and offer solutions.
Please take this as a final request to amend this behavior, and review the Site FAQ for guidance in asking well formed questions. Especially visit the link from that page, How to Ask Questions the Smart Way for discussion of things to consider when asking others for help.
From that page:
Quote:
If you are unwilling or unable to ask questions in a manner that allows us to help you, it's unlikely our community will be able to provide you a solution. Unfortunately, serial offenders who show wanton disregard for this request after multiple pointers may be asked to seek help elsewhere. We truly hope that isn't necessary, and assure you Linux and Open Source are extremely rewarding and well worth the learning curve in the long run.
Upon careful (&inferential) re-reading of #10, I think you neglected to say that you solved it, with the code you posted in #10. (In that case, mark Thread as Solv'ed with Thread Tools pull-down above #1)
IF not, here's my 'stern' reply (excuse the 'stern'):
You are, simply&clearly, **NOT** following the instructions!
Outputting a -1 *VIOLATES* their instructions & you FAIL.
Output *ONLY* a 7. Period. NOthing else.
Do it *THEIR* way (their site is probably NOT 'smart' enough to handle anything else.)
Make your code *EXACTLY* this (preferably delete, not comment, the last line tho # passes)
Code:
text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
index = alphabet.find(text[0].lower())
print(index)
#print(text.lower())
Do NOT 'ad lib': print alphabet.find(text[0].lower())
They are trying to teach you the concept of 'index'.
More: that website is very AI-lacking because this PASSES (with -1!)
Code:
text = 'Hello World'
alphabet = 'abcdefghijklmnopqrstuvwxyz'
index = alphabet.find(text[0].lower())
index = alphabet.find(text[0])
print(index)
The 'H' needs to be lower-cased to match the 'h' in alphabet, and index printed, regardless of value (-1 here!).
Continuing to torture that website, this passes, tho it prints 0 then -1!
Code:
text = 'H'
alphabet = 'H'
index = alphabet.find(text[0])
print(index)
index = alphabet.find(text[0].lower())
print(index)
I hope OP understands why 0 then -1! (Yes @OP? BtW @OP: please take all this with 'thick skin' i.e. don't be offended!)
(it also passes without the 2nd print, so its primitive 'AI' maybe just grep'ing for those last 2 lines!)
Upon careful (&inferential) re-reading of #10, I think you neglected to say that you solved it, with the code you posted in #10. (In that case, mark Thread as Solv'ed with Thread Tools pull-down above #1)
IF not, here's my 'stern' reply (excuse the 'stern'):
You are, simply&clearly, **NOT** following the instructions!
Outputting a -1 *VIOLATES* their instructions & you FAIL.
Output *ONLY* a 7. Period. NOthing else.
Do it *THEIR* way (their site is probably NOT 'smart' enough to handle anything else.)
Make your code *EXACTLY* this (preferably delete, not comment, the last line tho # passes)
Code:
text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
index = alphabet.find(text[0].lower())
print(index)
#print(text.lower())
Do NOT 'ad lib': print alphabet.find(text[0].lower())
They are trying to teach you the concept of 'index'.
More: that website is very AI-lacking because this PASSES (with -1!)
Code:
text = 'Hello World'
alphabet = 'abcdefghijklmnopqrstuvwxyz'
index = alphabet.find(text[0].lower())
index = alphabet.find(text[0])
print(index)
The 'H' needs to be lower-cased to match the 'h' in alphabet, and index printed, regardless of value (-1 here!).
Continuing to torture that website, this passes, tho it prints 0 then -1!
Code:
text = 'H'
alphabet = 'H'
index = alphabet.find(text[0])
print(index)
index = alphabet.find(text[0].lower())
print(index)
I hope OP understands why 0 then -1! (Yes @OP? BtW @OP: please take all this with 'thick skin' i.e. don't be offended!)
(it also passes without the 2nd print, so its primitive 'AI' maybe just grep'ing for those last 2 lines!)
Thanks for your detailed insights, and am following the many constraints, and am again stuck (the second time) at the step #80:
It states for the code:
Code:
# Append space to the message
if char.isalpha():
final_message += char
The not operator is used to negate an expression. When placed before a truthy value — a value that evaluates to True — it returns False and vice versa.
Add the not operator at the beginning of the if condition to check if the character is not alphabetic.
I made the change to the code as:
Code:
# Append space to the message
if not(not(char.isalpha())):
final_message += char
as, expect the logic to remain the same. But, it fails.
Then removed the outer 'not' too, still fails.
The error message is: Sorry, your code does not pass. Try again.
You should use the not operator in the condition of your if statement.
The error message is: Sorry, your code does not pass. Try again.
You should use the not operator in the condition of your if statement.
I think they have some test that is comparing your source code against the expected solution, and they don't expect the extra parentheses around the 'char.isalpha()' expression. Remove them and it passes (but this makes no difference in terms of the Python interpreter). Another example, introducing a differently named variable also "fails":
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.