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)

print "Beg pardon?"

Wednesday, May 7, 2014

The story so far:

As I mentioned in the introductory post, I didn't really develop a curiosity of programming until I had begun to build and upgrade my first Windows PC.  A friend of mine, we'll call him Boots, was more than happy to lend a hand in answering every question I had concerning computers.  He was the first to introduce me to the basic concepts and syntax of Python, giving me basic lessons that included the print() and input() functions, the while and for loops, if, then statements as well as a few modules like random.

At this point, one of my first assignments was to create a script that would simulate a coin flip.  After a little thought and a fair amount of frustration, here was the completed result:

while 1 == 1:
    import random
    a = raw_input("Coin Flip? (y/n)")
    if a == "y":
        x = random.randint(1, 2)
        if x == 1:
            print ("Heads")
        if x == 2:

            print ("Tails")

While this code is rather primitive compared to most other variations of a "Coin Flip" I've seen,  I was still no less excited to have created code that actually did what I wanted it to do.

However, being so caught up as a student in Chemical Engineering, I never made much time to learn much beyond this.  I once did attempt to write a script that would solve a quadratic formula, however it would consistently crash if imaginary numbers became present.  You can see that code here:
while 1 == 1:
    import math
    print ("Quadratic Formula")
    a = int(input("a: "))
    b = int(input("b: "))
    c = int(input("c: "))
    x = (b**2-(4*a*c))
    if x < 0:
        print ("Imaginary Number(s) Present")
    print (((-b)+math.sqrt(b**2-(4*a*c)))/(2*a))

    print (((-b)-math.sqrt(b**2-(4*a*c)))/(2*a))

I've been meaning to ask some more experienced programmers as to how to fix/rebuild this code, but it unfortunately was one of many tasks that has been put on the back burner.  Maybe this summer I'll even be able to fix it myself...


I'm also realizing my little logo at the top of the page looks like it reads "Coding with JWESI"...

Tuesday, May 6, 2014

Welcome + Introduction

Welp, this is probably the 12th blog I've started in my lifetime.  Those of you who know me know where my life stands right now; a married, full time student with a part time job at my local U-Haul branch.  My free time is limited, but I do have a goal for myself over the next year or two: learn programming.

I purchased my first PC around 2 years ago and have since been upgrading it piece by piece.  As a result, I'm spending more and more time with a keyboard glued to my finger tips.  With all of the free resources the internet provides, I fell in love with the idea of being able to create something with nothing more than some free software and a keyboard.

So that is what this blog will be, a log/journal following my experiences as I learn how to programming.  To be honest, this may be dull at times for readers.  This is more for my benefit.  My hope is that by keeping a blog I may be a little more motivated to achieve this goal.  I'll share the issues I come across, my completed code projects/assignments, jokes, anecdotes, and well, just about anything else I may consider relatable.

To begin, I'll work my way through Python 2.7, using Shaw's "Learn Python the Hard Way" and Sweigart's "Invent Your Own Computer Games with Python".  My coffee is brewing and the Ramen is boiling, time to get started.