Thursday, May 15, 2014

Day 1

Surprise, surprise.  Looks like I'm going to have a little more trouble keeping up with this than I thought.

I recall leaving off on the subject of "lists" within python, so that will be more than likely where I'll start back up again.  Last night, however, I spent a little time writing tiny scripts just to try to get refreshed on a few basics.

I made 3 versions of the same concept: a DnD (Dungeons and Dragons) dice bag.  The idea is the user would be able to type which dice they wished to use, such as a "d12" and be able to re-roll as many times as they wished by simply answering a "Re-roll? (y/n)" prompt.  To really stretch my memory, i thought I would try to use def for each dice function and using while to manage a repeating prompt. 

While i managed to utilize the random function without issue, and had each def function working as I wanted, I got stuck in an infinite loop...  I'll work on this and make a separate post.

Below is the condensed version.  It's primitive, but it does what I wanted it to do, which I'd consider a plus.


import random
while 1==1:
x = raw_input("""Choose a dice from the bag.
(d4, d6, d8, d10, d12, d20):""")
if x == 'd4':
print random.randint(1, 4)
elif x == 'd6':
print random.randint(1, 6)
elif x == 'd8':
print random.randint(1, 8)
elif x == 'd10':
print random.randint(1, 10)
elif x == 'd12':
print random.randint(1, 12)
elif x == 'd20':
print random.randint(1, 20)
else:

print "Beg pardon?"

No comments:

Post a Comment