Dec-27-2017, 05:31 PM
Ok, let first start I am currently overseas in Turkey. So, I am taking my courses online. I am doing introduction to coding. When is came to the basic math problems I was fine. (Keep in my mind I have not clue about coding at all). Now that I have moved to the function part of coding it wont do anything I type in. Sometime I type print "hello world" and that doesn't even work. My problem is we are supposed to do all the exercise in "Think Python: How to think like a scientist" I will type everything in to Phyton the exact way they do in the book and I get nothing but error.
Latest problem says to type (Below) Which I do....
def print_lyrics():
print "I'm a lumberjack, and I'm okay."
print "I sleep all night and I work all day."
If you type a function definition in interactive mode, the interpreter prints ellipses (...) to let you know that the definition isn’t complete:
>>> def print_lyrics():
... print "I'm a lumberjack, and I'm okay."
... print "I sleep all night and I work all day."
...
To end the function, you have to enter an empty line (this is not necessary in a script).
Defining a function creates a variable with the same name.
>>> print print_lyrics
<function print_lyrics at 0xb7e99e9c>
>>> type(print_lyrics)
<type 'function'>
The value of print_lyrics is a function object, which has type 'function'.
The syntax for calling the new function is the same as for built-in functions:
>>> print_lyrics()
I'm a lumberjack, and I'm okay.
I sleep all night and I work all day.
Once you have defined a function, you can use it inside another function. For example, to repeat the previous refrain, we could write a function called repeat_lyrics:
def repeat_lyrics():
print_lyrics()
print_lyrics()
And then call repeat_lyrics:
>>> repeat_lyrics()
I'm a lumberjack, and I'm okay.
I sleep all night and I work all day.
I'm a lumberjack, and I'm okay.
I sleep all night and I work all day.
But that’s not really how the song goes.
And I type it in verbatim and it will never Work I don't get the (...) when I get to Print Print_lyric() Nothing. I am so frustrated. Am even tried typing it in notepad and then pasting it. I have tried everyway I can... I have no idea what to do. I youtube it and people just type stuff in a bam works. I am about to fail my class any help would be greatly appreciated. I just do now anything about coding and all I have is this book. You can PM me or post here.
Latest problem says to type (Below) Which I do....
def print_lyrics():
print "I'm a lumberjack, and I'm okay."
print "I sleep all night and I work all day."
If you type a function definition in interactive mode, the interpreter prints ellipses (...) to let you know that the definition isn’t complete:
>>> def print_lyrics():
... print "I'm a lumberjack, and I'm okay."
... print "I sleep all night and I work all day."
...
To end the function, you have to enter an empty line (this is not necessary in a script).
Defining a function creates a variable with the same name.
>>> print print_lyrics
<function print_lyrics at 0xb7e99e9c>
>>> type(print_lyrics)
<type 'function'>
The value of print_lyrics is a function object, which has type 'function'.
The syntax for calling the new function is the same as for built-in functions:
>>> print_lyrics()
I'm a lumberjack, and I'm okay.
I sleep all night and I work all day.
Once you have defined a function, you can use it inside another function. For example, to repeat the previous refrain, we could write a function called repeat_lyrics:
def repeat_lyrics():
print_lyrics()
print_lyrics()
And then call repeat_lyrics:
>>> repeat_lyrics()
I'm a lumberjack, and I'm okay.
I sleep all night and I work all day.
I'm a lumberjack, and I'm okay.
I sleep all night and I work all day.
But that’s not really how the song goes.
And I type it in verbatim and it will never Work I don't get the (...) when I get to Print Print_lyric() Nothing. I am so frustrated. Am even tried typing it in notepad and then pasting it. I have tried everyway I can... I have no idea what to do. I youtube it and people just type stuff in a bam works. I am about to fail my class any help would be greatly appreciated. I just do now anything about coding and all I have is this book. You can PM me or post here.