Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 5th, 2005, 12:33 PM   #1
Cipher
Hobbyist Programmer
 
Cipher's Avatar
 
Join Date: Feb 2005
Location: /home/cipher
Posts: 123
Rep Power: 4 Cipher is on a distinguished road
Send a message via AIM to Cipher Send a message via MSN to Cipher
New Proggie Language!!YAY!

Well I have decided to learn Python. Does anyone know how to do hello world?!
__________________
And there was much rejoicing... Yay....
Cipher is offline   Reply With Quote
Old Mar 5th, 2005, 12:40 PM   #2
Fred
Programmer
 
Fred's Avatar
 
Join Date: Feb 2005
Posts: 67
Rep Power: 4 Fred is on a distinguished road
I take it, that you already have the python compiler:
print 'Hello World'
Not that hard, is it??
Fred is offline   Reply With Quote
Old Mar 5th, 2005, 9:06 PM   #3
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Smile

A little more advanced:
# this will print  Hello World!  10 times
for q in range(10):
  print "Hello World!"
Really advanced:
# this will spell it out for you
for c in "Hello World!":
  print c
Really, really advanced:
# this will spell it out for you with sound effect

import winsound

for c in "Hello World!":
  print c
  winsound.Beep(800,100)
__________________
I looked it up on the Intergnats!

Last edited by Dietrich; Mar 5th, 2005 at 9:22 PM.
Dietrich is offline   Reply With Quote
Old Mar 6th, 2005, 11:13 AM   #4
Fred
Programmer
 
Fred's Avatar
 
Join Date: Feb 2005
Posts: 67
Rep Power: 4 Fred is on a distinguished road
Show off!
Just to make me feel stupid..
Fred is offline   Reply With Quote
Old Mar 6th, 2005, 11:57 AM   #5
thechristelegacy
Expert Programmer
 
thechristelegacy's Avatar
 
Join Date: Jul 2004
Location: Somerset, Pa
Posts: 708
Rep Power: 5 thechristelegacy is on a distinguished road
Send a message via AIM to thechristelegacy Send a message via MSN to thechristelegacy
I prefer to to make it say it ten times like so
x = 0
while x < 10:
     print "Hello, World."
     x = x + 1
thechristelegacy is offline   Reply With Quote
Old Mar 6th, 2005, 2:05 PM   #6
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Red face

Quote:
Originally Posted by Fred
Show off!
Just to make me feel stupid..
You did it the simplest way!!! What's so stupid about that?
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Old Mar 6th, 2005, 2:13 PM   #7
Fred
Programmer
 
Fred's Avatar
 
Join Date: Feb 2005
Posts: 67
Rep Power: 4 Fred is on a distinguished road
I was jsut kidding with you...
Hope you did not take offense!?
Fred is offline   Reply With Quote
Old Mar 6th, 2005, 2:24 PM   #8
andy_m
Newbie
 
Join Date: Feb 2005
Posts: 8
Rep Power: 0 andy_m is on a distinguished road
If you really wanted to make "Hello, world!" difficult for yourself, you could do:
import sys
sys.stdout.write("Hello, world!\n")
andy_m is offline   Reply With Quote
Old Mar 6th, 2005, 2:27 PM   #9
Fred
Programmer
 
Fred's Avatar
 
Join Date: Feb 2005
Posts: 67
Rep Power: 4 Fred is on a distinguished road
Good thought...
What is actually the point of this complicated syntax for the 'print' statement?
Has it any special powers, that justify it's existens, or has it survived out of an older version of python? --> somewhat off topic, but it just interested me.
Fred is offline   Reply With Quote
Old Mar 6th, 2005, 2:40 PM   #10
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Talking

If you have wxPython v2.5 installed, you can really show it off!
# Hello World using Python 2.3 and wxPython 2.5

import wx

def create(parent):
    return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1STATICTEXT1] = [wx.NewId() for _init_ctrls in range(2)]

class Frame1(wx.Frame):
    def _init_ctrls(self, prnt):
        wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
              pos=wx.Point(326, 167), size=wx.Size(523, 173),
              style=wx.DEFAULT_FRAME_STYLE, title='Show it off!')
        self.SetClientSize(wx.Size(515, 133))

        self.staticText1 = wx.StaticText(id=wxID_FRAME1STATICTEXT1,
              label=' Hallo World!', name='staticText1', parent=self,
              pos=wx.Point(0, 0), size=wx.Size(515, 133), style=0)
        self.staticText1.SetFont(wx.Font(48, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, 'Comic Sans MS'))
        self.staticText1.SetForegroundColour(wx.Colour(255, 255, 0))
        self.staticText1.SetBackgroundColour(wx.Colour(0, 128, 64))

    def __init__(self, parent):
        self._init_ctrls(parent)


if __name__ == '__main__':
    app = wx.PySimpleApp()
    wx.InitAllImageHandlers()
    frame = create(None)
    frame.Show()

    app.MainLoop()
Go ahead, call me a show-off!
Actually I cheated a little, and used the Boa Constructor visual IDE. I only entered "Hello World!" and set the font and colors, clicking on the right places. Oh Gee! I am not a show-off after all!
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:54 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC