## Friday, October 9, 2009

### I kick so much ass.

While in Computer Science, alongside taking my notes and following the teacher on the computer, I coded a program that would randomly choose a team of six Poke'mon for me using Python's import.random and random.randint commands. And it WORKS.

...now I just need to figure out how to keep it from choosing the same number more than once. Any ideas, computer guys?

My code is this, required indents not included:
import random

for team in xrange(6):
chosen = random.randint(1, 15)
if chosen == 1:
print "Kala-Nemi"
elif chosen == 2:
print "Sentinel"
elif chosen == 3:
print "Aeon"
elif chosen == 4:
print "Leventhan"
elif chosen == 5:
print "Colossus"
elif chosen == 6:
print "Samus Aran"
elif chosen == 7:
print "Kagegami"
elif chosen == 8:
print "Grell"
elif chosen == 9:
print "Jack Frost"
elif chosen == 10:
print "EVA-01"
elif chosen == 11:
print "Kenshin"
elif chosen == 12:
elif chosen == 13:
print "Takoyaki"
elif chosen == 14:
print "Ninetails"
elif chosen == 15:
print "Enigma"
else:
print chosen

dick said...

Me no speaka french

bobn said...

Since you chose Python and then posted it in a format that doesn't respect white-space, it's unuseable from here.

That is why I never use Python. Perl Rulez! Syntactically significant white-space sux massively.

Silver the Evil Chao said...

Python's used as kind of an introduction to programming. ^.^;; Last year, it was Java.

I didn't necessarily post it so it could be used, just so that you programmers out there would have a general idea of what techniques I was using so I could be helped out. ^.^;;

bobn said...

Java? They have no mercy. Although it does get used in the so-called real world.

Anyhow for your program: You could put all the names in a list. Then use chosen to index the name out of the array.

As in: (watch out for syntax, I don't really know python):

names = [ "Kala-Nemi", "Sentinel", "Aeon", ... ]

chosen = random.randint(1, 15)

print names[chosen]

bobn said...

Oops, prolly need to random.randint(0, 14), since arrays index the first element at 0.

"whatever" ;)