Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: I need dire help with my Python.  (Read 5541 times)

Asheron

  • Bay Watcher
  • Look in to my eyesssss.
    • View Profile
    • http://www.ihavenoideathissiteexcisted.com
I need dire help with my Python.
« on: September 10, 2008, 12:42:46 pm »

I am going to ( try ) to help with the Spogue project and as such I decided to polish my python programming skills. ( It's like, three years ago and I wasn't that good at it either )
Now, I've gotten past the basics again. I'm going to start a very small project of my own, and for it, I need randomisation ( any with more then ten possible outcomes is fine ).

Now, how do I incorporate a randomisator-thingie in to my program?

Spoiler (click to show/hide)

EDIT: I can't believe only nine people read this post yet. I mean, look at the title!
« Last Edit: September 10, 2008, 01:12:12 pm by Asheron »
Logged


Quote from: Toady One
Did you just post a bunch of vegi-dicks on my board?  I've been trying to combat forum devolution a bit, and that involves fewer vegi-dicks!
Quote from: Yahtzee
Yes, random is funny, isn't it? Sometimes I set up a random number generator when I need a good laugh.

Fualkner

  • Bay Watcher
  • My glasses split light.
    • View Profile
Re: I need dire help with my Python.
« Reply #1 on: September 10, 2008, 03:41:58 pm »

Ah. This is very easy.

Code: [Select]
import random

test1 = random.randrange(10)
test2 = random.uniform(0,10)
print test1
print test2

Both will give random numbers. Randrange will give out integers, uniform will give out numbers to the 16th decimal place.

I am currently involved in a project, but I'd love to offer input, try to optimize code etc. This sounds like a great idea, I'm working on a roguelike myself.
Logged

rickvoid

  • Bay Watcher
    • View Profile
Re: I need dire help with my Python.
« Reply #2 on: September 10, 2008, 03:53:49 pm »

All I read was Dire Python.

 ;D
Logged

Makrond

  • Bay Watcher
  • Like fuzzy dice, only more slicey
    • View Profile
Re: I need dire help with my Python.
« Reply #3 on: September 10, 2008, 08:38:46 pm »

'Tis a shame you're not using C++. Only because you could then steal Toady's randomiser code (from Battle Champs)...

Err, not that I'm saying it's a good idea or anything...
Logged
Quote from: Jusal
Darwinism? Bah! This is Dwarvinism!

Asheron

  • Bay Watcher
  • Look in to my eyesssss.
    • View Profile
    • http://www.ihavenoideathissiteexcisted.com
Re: I need dire help with my Python.
« Reply #4 on: September 11, 2008, 09:36:49 am »

Ah. This is very easy.

Code: [Select]
import random

test1 = random.randrange(10)
test2 = random.uniform(0,10)
print test1
print test2

Both will give random numbers. Randrange will give out integers, uniform will give out numbers to the 16th decimal place.

I am currently involved in a project, but I'd love to offer input, try to optimize code etc. This sounds like a great idea, I'm working on a roguelike myself.

I thank thee a hunderd times. Let your offspring be rich and numerous.
« Last Edit: September 11, 2008, 11:02:48 am by Asheron »
Logged


Quote from: Toady One
Did you just post a bunch of vegi-dicks on my board?  I've been trying to combat forum devolution a bit, and that involves fewer vegi-dicks!
Quote from: Yahtzee
Yes, random is funny, isn't it? Sometimes I set up a random number generator when I need a good laugh.

Cthulhu

  • Bay Watcher
  • A squid
    • View Profile
Re: I need dire help with my Python.
« Reply #5 on: September 11, 2008, 03:26:51 pm »

Have you tried Enzyte?
Logged
Shoes...

Asheron

  • Bay Watcher
  • Look in to my eyesssss.
    • View Profile
    • http://www.ihavenoideathissiteexcisted.com
Re: I need dire help with my Python.
« Reply #6 on: September 12, 2008, 09:19:14 am »

Have you tried Enzyte?
Why use Enzyte when you can pray to the demon gods for a rich offspring?
Logged


Quote from: Toady One
Did you just post a bunch of vegi-dicks on my board?  I've been trying to combat forum devolution a bit, and that involves fewer vegi-dicks!
Quote from: Yahtzee
Yes, random is funny, isn't it? Sometimes I set up a random number generator when I need a good laugh.

Asheron

  • Bay Watcher
  • Look in to my eyesssss.
    • View Profile
    • http://www.ihavenoideathissiteexcisted.com
Re: I need dire help with my Python.
« Reply #7 on: September 12, 2008, 04:11:52 pm »

Code: [Select]
def menu():
    print "Hello, welcome to guess the number v 0.01."
    print "Press any number to guess ( with a maximum of ten )."
    print "Press both numbers and letters to crash the game. ;)"

print menu()
a = 1
import random
test1 = random.randrange(10)

while a == 1:
 y = input("Prompt: ")
 if test1 != y:
     if test1 > y:
         print "Go higher."
     if test1 < y:
         print "Go lower."
 else:
     print "You win! Have a cookie."
     test1 = random.randrange(10)
     a = 1

Woohoo! Me using the randomiser-thingie effectively for the first time! ^^

Yes, I was bored. I wanted to see if I could come up with something in 30 seconds.
Logged


Quote from: Toady One
Did you just post a bunch of vegi-dicks on my board?  I've been trying to combat forum devolution a bit, and that involves fewer vegi-dicks!
Quote from: Yahtzee
Yes, random is funny, isn't it? Sometimes I set up a random number generator when I need a good laugh.

Fualkner

  • Bay Watcher
  • My glasses split light.
    • View Profile
Re: I need dire help with my Python.
« Reply #8 on: September 12, 2008, 09:56:41 pm »

Looks good, but you should use elif after the first of a string of if statments. It can process it better, I believe. Nothing wrong with your program that I can see, good work.

Now make a version with uniform() and watch your friends and family cuss with utter vile anger.
Logged

lambskin

  • Bay Watcher
    • View Profile
Re: I need dire help with my Python.
« Reply #9 on: September 12, 2008, 11:39:47 pm »

Feed it blueberries, that should solve any constipation.
Logged
STRIKE THE ETC.

PowerGoal45, MEET THE CYBERFIST, (Future): You use your iron geared prosthetic hand to crush a piece of stone in front of the cowering goblin, and it passes out.

Asheron

  • Bay Watcher
  • Look in to my eyesssss.
    • View Profile
    • http://www.ihavenoideathissiteexcisted.com
Re: I need dire help with my Python.
« Reply #10 on: September 13, 2008, 10:53:51 am »

I don't know what uniform() is :(

Spoiler (click to show/hide)


« Last Edit: September 13, 2008, 10:56:02 am by Asheron »
Logged


Quote from: Toady One
Did you just post a bunch of vegi-dicks on my board?  I've been trying to combat forum devolution a bit, and that involves fewer vegi-dicks!
Quote from: Yahtzee
Yes, random is funny, isn't it? Sometimes I set up a random number generator when I need a good laugh.

Fualkner

  • Bay Watcher
  • My glasses split light.
    • View Profile
Re: I need dire help with my Python.
« Reply #11 on: September 13, 2008, 03:07:38 pm »

I don't know what uniform() is :(

It's another random function, gives a random number with 16 decimal places. It's impossible to guess because.... well, the obvious reasons.

Also... I spotted a little thing at the bottom of that code...

Code: [Select]
b = 0
easy = 0

b = b + 1
easy += 1
if b == easy:
 print "The values are equal"
else:
 print "Well damn, I've messed up."

Just an easier way of writing the same thing.
Logged

Asheron

  • Bay Watcher
  • Look in to my eyesssss.
    • View Profile
    • http://www.ihavenoideathissiteexcisted.com
Re: I need dire help with my Python.
« Reply #12 on: September 14, 2008, 04:04:58 am »

I don't know what uniform() is :(
It's another random function, gives a random number with 16 decimal places. It's impossible to guess because.... well, the obvious reasons.

Oooh... you meant random.uniform(). I thought uniform() was a function on it self.
Logged


Quote from: Toady One
Did you just post a bunch of vegi-dicks on my board?  I've been trying to combat forum devolution a bit, and that involves fewer vegi-dicks!
Quote from: Yahtzee
Yes, random is funny, isn't it? Sometimes I set up a random number generator when I need a good laugh.