2018-02-20 23:21:31

True. What makes .NET so nice is that you can mix managed and unmanaged code. Also, about pointers, pointers in C++ are not as scary as some people make them out to be. In fact, they're very easy to work with. You usually never have to do manual pointer cleanup because C++ usually handles that for you either upon program exit or upon scope exit. And with C++11, 14 and 17's new STL components, you now have std::smart_ptr and std::shared_ptr to use too, which both free themselves when no longer used.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2018-02-24 18:39:15

so one of my first many questions to come.
when creating strings, why cant I just use tripple quotes or ticks all the time? is there a disadvantige in doing so?

2018-02-24 19:54:19

You basically use triple quotes or triple ticks when you want to write multiline strings. This does not mean that string needs to be necessarily multiline, but writing single-line strings in tripple quotes makes no sense, although it's not an error.
Of course, instead of using multiline strings, you can just use escape sequences such as \n or \r, but it makes things less readable for code writer. For example:
"I'm a good boy.\nI'm the best guy in school.\nMy friends really like me."
Compare with this:
"""I'm a good boy.
I'm the best guy in school.
My friends really like me."""
You see, the second version as multiline string is much more readable.

2018-02-24 19:58:35

Let me add something:
I personally prefere to enclose strings in quotes, unless I have the following situation, for example, if I wanna have a message box that displays the user to click a button. I want the name of that button to be quoted, so I will enclose this in apostrophes like this:
'Please click "OK" to continue'
That way, I don't need to escape quotes to force displaying them inside a string by using escape sequence \" (backslash quote).

2018-02-24 21:56:01

I have a slight issue. when ever trying to type a script in a notepad and pasting it into the python the ctrl v doesn't work. anyway I can paste?

2018-02-24 23:54:04

you can do by pressing alt plus space, edit, paste

Paul

2018-02-25 01:52:33

I usually just save to a file with notepad, then run it in python by importing . IIRC, this doesn't work so well if you want to test changes, since I don't think python will update the module if you try to import it again, unless it failed to import via an error or something. Could have that backward, though.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2018-02-25 02:36:59

so now I'm getting into if statements, and just pasting the contense of the file doesn't work.
I want to get input from the user then use if statements to print out different messages depending on what was entered, however, when I paste it into the python prompt it just sits there. no errors, no anything. what am I missing here?

2018-02-25 03:15:10

When you start something like an if, while, class, or function, Python expects an indented block to follow. The editor therefore waits until you enter an unindented line, or leave a blank line, before it tries to execute the code.
If you're pasting an if with a block attached, I'm not really sure what's going on.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2018-02-25 03:52:48 (edited by magurp244 2018-02-25 04:05:18)

Another way to do it would be to save your script in notepad or similar text editor and run it from a command prompt, as python files are just plain text files with a renamed extension. For example: "python yourscript.txt", though to avoid confusion between file types you should probably save your scripts with a *.py extension instead of *.txt.

-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

2018-02-25 05:05:11

I'm not sure I understand? When do I paste in a blank line?  If you're talking  about me having code after the if statement, yes, I do.

2018-02-25 05:49:44

You need to press enter so that Python knows you're done with the indented part.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2018-02-25 12:05:48

for example you do this

think this is the interpreter
>>> input = raw_input("enter something")
>>> if input == 'hi':
...  print "hello"
...
this means after you write the code you'll have to press enter one more time and the interpreter will execute your code.
note: I'm using indentations with 1 space only

Paul

2018-02-25 18:04:13 (edited by amerikranian 2018-02-25 18:07:43)

so this is what i'm trying to paste into my python prompt. I think if someone can point out what am I doing wrong it would clear it up for me: (Note, I'll use a > symbol to represent a single space as AG forum doesn't like python's indentation.)
>user_input = input("enter something")
>if user_input == "hi"
>>print("hello")

I'm sorry for so many questions guys, I'm trying to understand this.

2018-02-25 18:21:24

you are missing the colons after the condition if
try putting this
>user_input = input("enter something")
>if user_input == "hi":
>>print("hello")

Paul

2018-02-25 19:43:55 (edited by amerikranian 2018-02-25 19:57:04)

alright: more problems. Yea! Who loves problems?
When I pasted in the following, the python prompt returned me a big fat nothing.
I will post the code below, using > again to represent a single space.
>user_input = input("enter something")
>if user_input == "hi":
>>print("hello") #this causes an error with the indentation
That script does nothing at all besides the error.

It also should be noted that I have tried something like this:
>user_input = input("enter something.")
>if user_input == "hi":
>print("hello") #the script returns another error about the indentation.

Finally, I have tried something like this:
>user_input = input("enter something")
>if user_input == "hi":
print("hello") #this is the only part that works. The input and the if statement get skipped.

2018-02-26 22:21:49

I am using a book called how to think like a computer scientist found at the following link
http://openbookproject.net/thinkcs/python/english3e/
If you go to chapter 3, you'll see that the book suggests you to enhance the turtle program by allowing the user to set the title of the window and such. Trouble is, the input statement doesn't work. I'll post the code below, or at least the important part.
import turtle
wn = turtle.Screen
title = input("enter something")
wn.title(title)

If I run this, it would make the title the
wn.title(title)
Line instead of asking for input. I tried getting input before initializing the screen but, no luck.

2018-02-26 22:28:04

Try saving it to a file, and run that. If the results are the same, something odd is happening (maybe spaces are showing up as the wrong character or something like that?). If it works from a file, then the interpreter is having trouble with pasting some things.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2018-02-26 23:49:34

This might be a bit silly, but how do you run a file from an interpreter? Do you just paste in the file path?

2018-02-27 02:06:16

From the Python interpreter, you import it. If the file is HelloWorld.py, you would type
>import HelloWorld
And that would do it. I'm not sure that there's an easy way to repeat this without restarting the interpreter, though, if you make changes afterward.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2018-02-27 04:29:01

Does the file have to be in a certain location?

2018-02-27 06:14:59

No. Anywhere will do.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2018-02-27 08:00:14 (edited by pauliyobo 2018-02-27 08:02:19)

or you can run it from the CMD open the command prompt in the path in which your file is, and run python filename.py
post 42:
This may not work, but you can try this
import turtle
I'll use the greater sighn for indentation

wn = turtle.screen
while 1:
>title=str(input("enter the screen title"))
>wn.title(title)
>break

if the script should keep asking you the title, remove the break statement.
REGARDS

Paul

2018-04-06 01:04:43

so, consider the following code: Note: indentation is a greater than sign:
def my_fun(a):
>a = a + 1
>x = a
>print(a)
>print(x)

x = 3
my_fun(x)

So I now have a question. If you run this, you will be printed a value of 4 4. Now, here's the fun part. If you type in x in the interpreter it will say, clearly, 3, but wait. I had a statement in the my_fun function that should have set x to 4, so why is it 3? Ferther more, if you type in a, the following will appear:
Traceback (most recent call last):                                             
  File "<stdin>", line 1, in <module>                                           
NameError: name 'a' is not defined                                             
but but but... I clearly set a to 4! So why, why in the world does the stupid thing reset and acts as though I have never defined a variable called a? After all, I did do it. So my question is how? How can I change the variable outside of a function instead of declaring a variable that lasts only till a function finishes running? Is it something to do with the return statement? I'd be really grateful for any help and would also appreciate if you provided a code snippid or some such.

2018-04-06 01:23:34 (edited by thggamer 2018-04-06 01:29:32)

In Python, when you run the "my_fun" function, the variables are created
inside the function.
When the function returns or when it ends, Python removes the
variables that are inside the function and restores the
variables that are declared outside it.
This is called a namescope (the function has a namescope which their
variables are declared, and the script has another).
When you tipe x in the interpreter, you are referencing the x of the
script namescope because the function has already ended.
Edit: to modify a variable inside a function, declare it as global so it
can be seen on the script namescope. See the example:
>>> def set_x_and_print_it():
...     global x
...     x = 3
...     print(x)
...
>>> set_x_and_print_it()
3
>>> x
3