I may sound very dump lol - but getting everything straight in the first place is better than not to ask at all - comments

Beginner with python - I am taking a class with data camp and in one exercise, I used " # " to add my comment, after running the code, the comment is not showing up I believe it should right.
Did I miss anything or is the exercise screen has a bug or something? This question is too simple, I may sound dump but rather focus on learning the basics before moving on. lol.

If your line starts with the comment sign #, then the python interpreter will ignore this line.
So if you run these lines:
print("Hello earth")
# print("Hello moon")
The output will be only Hello earth

Related

What does (#)/[some_folder] mean at the beginning of that Shell script example?

I have no serious tech background, just know some Python basics. Became interested in Flask, read the Flask tutorial, saw that Flask requires setting some environment variables. Didn't know what that is, this led me to Linux and now I'm sort of addicted to that Linux Bible, I have the 9th edition. Normally man pages + Google always have answers for me. Not this time.
So there's an example backup script on p. 168, the second line right after the shebang line is:
# (#)/my_backup
The /my_backup part does not show up anywhere in the example script again and I get that this is commented out but it bugs me that the (#) part looks like being meaningful and I can't find any information on this. Searching the bash man pages only has unrelated results and Google wasn't helpful either.
Can anyone explain to me why this line is in the example script? I understand all of the script except the reason why the 2nd line looks how it looks. Have I overlooked something important while reading the book?

How to get started posting a question with Stack Overflow?

I know this is going to sound extremely stupid but I honestly cannot figure out how to post a question I have here for a program I am trying to make.
Whenever I paste my code into the code section this website tells me I have not formatted correctly. I triple check everything and it is all perfectly formatted. It is strange though because my code ends up being halfway into the place where I am suppose to describe the issue. So I am definitely doing this wrong.
Would somebody please walk me through a simple tutorial so I can finally ask my questions?
Honor to help you, I think you can first learn how to use markdown.
And this is two useful tutorial I read when I am learning.
Perfect question : WRITING THE PERFECT QUESTION
Use Markdown effectively : Markdown Getting Started
As for the display of code you mention above, you can use triple ``` to surround the code like this
import math
print('hello world')

one /t creating two tabs in Ruby?

I'm doing Zed Shaw's "Learning Ruby the Hard Way," exercise 24, and have come across a problem. There is a point where he has us type this:
poem = <<END
\tThe lovely world
with logic so firmly planted
cannot discern \n the needs of love
nor comprehend the passion from intuition
and requires an explanation
\n\t\twhere there is none.
END
puts "-------------"
puts poem
puts "-------------"
and somehow my code is doing this:
-------------
The lovely world
with logic so firmly planted
cannot discern
the needs of love
nor comprehend the passion from intuition
and requires an explanation
where there is none.
--------------
-My 'lovely' line tabbed twice. I also think my line "where there is none." might be over too far as well...
I've checked for an extra space somewhere. after "<<END" and after the first and second "-----." I've undone the tab to see if it would tab w/o it but it doesn't. I had it on the same line as <<END with an \n\t, just to see if that would work but I got an error message. Anyone have an idea what's going on? and how to fix it??
Edit: I'm using Ubuntu 14.04, and here is my screen shot screenshot2
Hopefully this helps you (and me).
I just realised I haven't shown what he says it's supposed to look like so here's that. screenshot3
It could be just your terminal outputs tabs quite widely, as 8 spaces. Try something simpler to see the tab width, like this:
puts "tab\twidth"
puts "tab........width"
You can change tab width in your terminal by (for example to 4 spaces)
tabs 4
You can also look into man page or settings of your terminal.

Python syntax error with "else"

I am using IDLE and Python 2.7. I am new to python and programming in general so sorry if this is extremely newbish, which it probably is.
Anyway, I'm following along and taking notes with python video and I was using IDLE and I keep getting this syntax error http://i.imgur.com/9urr4IW.png . I tried moving "else:" back to see if that was the problem but that didn't help. Just giving me a hint would help lol, thanks.
White space is significant in loops and if-else in python, I believe you wanted something like
if sister_age > brother_age:
print("Sister is older")
else:
print("Brother is older")
I solve your problem and solution is very simple...you just have to start the else part from the start of IDLE like i have done you will get your desirable output .

How to run Ruby file on Sublime Text

I have a file named add_and_power.rb as below, and want to run it on Sublime Text.
def add_and_power a,b
(a+b)**(a+b)
end
puts "First number please? "
input1 = gets
puts "Second number please? "
input2 = gets
puts "The result is: ", add_and_power(input1.to_i, input2.to_i)
I run cmd+b, but it just displays,
First number please?
Second number please?
The result is:
1
[Finished in 0.9s]
I want to input 2 and 3 to get the answer. How can I make Sublime Text 2 ask for inputs and give back an answer?
If you want to run code within ST2, check out the SublimeREPL plugin, available through Package Control. You can either use IRB or pry, which is a lot more powerful. You can use it as a classic REPL (think Clojure or LISP), and you can also transfer your code from one tab into the running REPL in another tab by selection, line range, or block.
In some of my tests the pry REPL doesn't handle input through gets very well, but I haven't played around with it that much. YMMV - Edit - As AGS mentions below, use my_var = $stdin.gets for interactive input within SublimeREPL Ruby.
I highly highly recommend SublimeREPL, as it's a really powerful tool, and is self-contained within ST2, so you don't have to keep flipping back and forth to your terminal, saving and reloading your programs.
It is possible to run your programs when you need to have user input from the keyboard, but it isn't very nice.
When I do so, I need to input from a terminal that opens when I run Sublime, while also reading the response from the program at the bottom of the editor.
It is simply easier to run the program from the console/terminal.
So, the answer is, while it is possible to do so, there are concerns. You may need to use STDOUT.sync = true or STDOUT.flush to help manage the buffer with the OS, you have two thing to look at, while doing so... yuck.
It may not be the answer you are looking for, but as a developer, you should be comfortable running things from the console/terminal.

Resources