NZGames.com Forums
Register FAQ Calendar Mark Forums Read

Go Back   NZGames.com Forums > General > Coders' Forum
User Name
Password

Reply
 
Thread Tools
Old 13th May 2011, 14:40     #1
xpandnz
 
Python coding

So I am doing CompSci 111 at UA at the moment as general ed and we use Pyhthon to code programs. I used to write basic code when I was like 12 or so on the C64 and could write silly little games.

Looking at python, it seems very similar but without the numbers to refer to when using GOTO and functions like that.

Question is, has anyone used Python here much and have been able to create some pretty nifty applications?
__________________
asghasdhoaidhoqhdoqjwod;asdadas
  Reply With Quote
Old 13th May 2011, 14:56     #2
scorpious
 
I'm currently studying python at UC. From what I can tell its not as powerful as something like c but is far easier to learn and a lot quicker to use. I'm currently trying to create a game dodgem

Your right, it doesn't have the GOTO command but the functions work much the same way and are much easier to debug than GOTO.
  Reply With Quote
Old 13th May 2011, 20:14     #3
DrTiTus
HENCE WHY FOREVER ALONE
 
I like Python. It has arbitrary precision integers!

A lot of cool projects use Python, so while you can't write a device driver with it, it's still pretty powerful in its own way.
__________________
Finger rolling rhythm, ride the horse one hand...
  Reply With Quote
Old 13th May 2011, 20:31     #4
xpandnz
 
I'm just new to it and the only programming I have done is BASIC years ago so I'm still trying to get my head around certain things.

For example:

GOTO was the best thing ever for me when I used basic. Say if I create a 3d6 random generator to roll 3 6 sided die, then at the end of the random program I want to say "Press Enter to roll again" i could have said goto line x to keep looping the code.

But with python because I don't have that I wonder if I need to use the while command. So if i write:

enter = "y"
while(enter = "y"):
( random die number code here )

enter = input("Roll again? y or n")

Would that code cause my loop to keep going until another character was entered?

Once I figure out how to replace my understanding of GOTO then I can start having tons of fun writing shit. Will also need to learn how to draw shapes with it too.

Also, can you convert your python code into an executable?
__________________
asghasdhoaidhoqhdoqjwod;asdadas
  Reply With Quote
Old 13th May 2011, 20:58     #5
LordP
 
You need to put the second 'enter' bit inside the while loop, otherwise you'll end up with an infinite loop rolling dice
Code:
#!/bin/env python while (True): print("Rolling dice!") if (raw_input("Roll again? (y/n) ") == 'n'): break
__________________
"Nothing is so smiple that it can't be screwed up."
  Reply With Quote
Old 13th May 2011, 21:00     #6
LordP
 
Oh, and bookmark http://docs.python.org
__________________
"Nothing is so smiple that it can't be screwed up."
  Reply With Quote
Old 13th May 2011, 23:17     #7
xpandnz
 
Chur. I got hat die roll going nicely. Works a treat.
__________________
asghasdhoaidhoqhdoqjwod;asdadas
  Reply With Quote
Old 14th May 2011, 12:14     #8
scorpious
 
I found this very useful when I started programming

http://en.wikibooks.org/wiki/Non-Pro...for_Python_2.6
  Reply With Quote
Old 14th May 2011, 20:19     #9
xpandnz
 
I'll use this thread to ask questions now that I find it impossible to find using google.

If I allocate certain values or strings to variables, is there there a way to random pull a variable and print it?

For example, I might have a deck of cards mapped out to variables. And I want the random command to pull any card from that list I have made. What would the command be?
__________________
asghasdhoaidhoqhdoqjwod;asdadas
  Reply With Quote
Old 14th May 2011, 20:36     #10
DrTiTus
HENCE WHY FOREVER ALONE
 
Sounds like you want to have a list of variables (eg names of cards) and define a function to randomly pick a number (which is the list index eg 0 to 51) and return the element of the list referenced by that number.

http://docs.python.org/tutorial/introduction.html#lists
http://docs.python.org/tutorial/cont...ning-functions
__________________
Finger rolling rhythm, ride the horse one hand...
  Reply With Quote
Old 16th May 2011, 13:16     #11
Baal
 
Quote:
Originally Posted by xpandnz
Once I figure out how to replace my understanding of GOTO then I can start having tons of fun writing shit.
You can look at GOTO as basically an antiquated relic of completely procedural languages where it was impossible to refer to a chunk of code unless you reset to that point.

So rather than resetting to a point in your code & running through it again to execute common code, you compartmentalise that code within a function or an object method & call that function/method where needed.

http://en.wikipedia.org/wiki/Goto#Alternatives

Have a read just so you're not coding like it's 1970.
__________________
Your a homo.
  Reply With Quote
Reply


Thread Tools

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

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



© Copyright NZGames.com 1996-2024
Site paid for by members (love you guys)