Python Forum
Completly lost about to fail my class!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Completly lost about to fail my class!
#1
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.
Reply


Messages In This Thread
Completly lost about to fail my class! - by crakacheezy - Dec-27-2017, 05:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I am completely lost on this homework assignment a36 1 1,841 Feb-21-2022, 06:01 AM
Last Post: buran
  Very Lost vollynez 3 1,956 Oct-02-2020, 09:09 PM
Last Post: Yoriz
  I got lost in the program Gadev 1 1,938 Nov-11-2018, 05:50 PM
Last Post: j.crater
  I keep getting errors and I'm lost! samjonsnell 9 5,120 Oct-28-2018, 11:38 PM
Last Post: samjonsnell
  test..and I'm already lost sannixinc 1 2,572 Feb-22-2018, 09:09 PM
Last Post: glidecode

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020