noob need help with hello world

This is the place for queries that don't fit in any of the other categories.

noob need help with hello world

Postby 1885 » Sun Jun 08, 2014 12:18 pm

I'm running gentoo linux
Code: Select all
cwc@azzerare ~/python $ python
Python 3.3.3 (default, Jan 19 2014, 06:11:24)
[GCC 4.7.3] on linux
Type "help", "copyright", "credits" or "license" for more information.

Why will this code not work? I ran python hello.py
Code: Select all
print "Hello World!"
print "Hello Again"
print "I like typing this."

But this will:
Code: Select all
print ("Hello World!")
print ("Hello Again")
print ("I like typing this.")

It's no big deal but I'd like to know why I need the parentheses ()
Last edited by Mekire on Sun Jun 08, 2014 12:21 pm, edited 2 times in total.
Reason: First post lock. Code tags.
1885
 
Posts: 3
Joined: Sun Jun 08, 2014 12:09 pm

Re: noob need help with hello world

Postby Mekire » Sun Jun 08, 2014 12:20 pm

The first is python 2 code. You are using python 3. In python 3 print is a function, not a statement.

-Mek
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: noob need help with hello world

Postby 1885 » Sun Jun 08, 2014 12:37 pm

Mekire wrote:The first is python 2 code. You are using python 3. In python 3 print is a function, not a statement.

-Mek


Wow. good to know! It would seem logical to stick with python 3
thanks for the line.

Is this a good forum?
I have some other code I am trying to understand.
I do not understand why dragon(5) calls a function that has 4 parameters unless is it polymorphic and python understands dragon(5) sets the level

Code: Select all
from turtle import right, left, forward, speed, exitonclick, hideturtle
 
def dragon(level=4, size=100, zig=right, zag=left):
    if level <= 0:
        forward(size)
        return
 
    size /= 1.41421
    zig(45)
    dragon(level-1, size, right, left)
    zag(90)
    dragon(level-1, size, left, right)
    zig(45)
 
speed(0)
hideturtle()
dragon(5)
exitonclick() # click to exit
Last edited by Yoriz on Sun Jun 08, 2014 12:43 pm, edited 1 time in total.
Reason: Added code tags.
1885
 
Posts: 3
Joined: Sun Jun 08, 2014 12:09 pm

Re: noob need help with hello world

Postby Yoriz » Sun Jun 08, 2014 12:45 pm

Please use code tags when posting code to preserve the indentation.
Read the new user read this link in my signature for info on how to post.

The function dragon has been given default values that are used when no new values are given when the function is called.
see the following link in the python tutorial
https://docs.python.org/3/tutorial/controlflow.html#default-argument-values
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 827
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: noob need help with hello world

Postby 1885 » Sun Jun 08, 2014 1:41 pm

Thank you so much for the reply and the link.
This seems to be an excellent forum. I will learn a lot!
Thanks again!
1885
 
Posts: 3
Joined: Sun Jun 08, 2014 12:09 pm


Return to General Coding Help

Who is online

Users browsing this forum: buran and 6 guests