• entries
6
2
• views
501

I started this blog having written about 10 small programs in Python and getting most of them to work - 90 pages into my first python book.

My goal is to use game engines to produce my own indie video games based on my art, writing and design.

I started out in Python, now I'm studying rpg maker and unity.

I'll talk about things I did wrong and what I learned. Hopefully I can chart my progression on this blog.

For more of my stuff check out my website: http://imagineermike.com

## first time coding in python on ios: Guess My Number (rated M: language)

So I used python 3 for ios on my ipad to do part one of this assignment. Part One: create a guess my number game: numSpecial = 0 time = 0 guesses = 0 g = 0 i = 0 import random numSpecial= random.randint(1,9) print ("guess my nmber, biatch! between 1 and 10") while g!= numSpecial:     time = time + 1     if time > 5:         print ("you took too long, loser")     elif g > numSpecial:         print ("too high, shithead")         guesses = guesses + 1     elif g < numSpecial:         print ("too low, asshole")         guesses = guesses + 1     elif guesses > 10:         print ("I have had enough of your shit")     else:         print ("you found an error")     g = int(input("what is your guess?"))     if g == numSpecial:         print ("you guessed right, you are not as stupid as I thought.")         i = input ()   Part Two: figure out where in the program the computer recognises time and place a time limit on the game.   And no it doesn't have an ending because I haven't covered ending a program in the text yet.

## still tinkering with python

Q: assignment that flips a coin 100 times and gives you the total amount of heads and tails. A: I started by making it flip a coin 5 times so I could easily watch it working and fix bugs. I don't think it actually flips the coin exactly 100 times, can you spot the error? It took me an hour to get it to work:   import random
def variables ():
tails = 0
coinCount = 0
againPlay = "y"

def game():
tails = 0
againPlay = "y"
coinCount = 1
while coinCount > 0:
if againPlay != "y":
print (" and ", tails, "tails.")
end = input ("You're all done now!")
nmCoin = random.randrange(2)
if coinCount > 100: againPlay = "n"
if nmCoin == 1:
coinCount = coinCount + 1
elif nmCoin == 0:
tails = tails + 1
coinCount = coinCount + 1
else:
print (" and ", tails, "tails.")
end = input ("You're all done now!")

variables ()
game ()

## my first program in python

I wrote my first program (not including the false start last time I attempted programming) in Python... and it works! after a few bug fixes it's actually quite small and some would think insignificant. But I'm getting used to the syntax and form of the language.   print ("hello") print ("nwhat are your 2 favourite foods of all time?") food1 = input ("nt1.") food2 = input ("nt2.")   print ("I have made ",food2+food1," for you!")   input ("press a key to exit and enjoy your meal :)")

## my 2nd program in python

tip15 = 0
tip20 = 0
price = input ("how much did your meal cost?")
tip15 = int (price) * .15
tip20 = int (price) * .2
print ("A 20% tip would be ",tip20," and a 15% tip would be",tip15)
input () I wrote a tipper program for an exercise.
It's a simple program and it took 20mins to write including several bug fixes,
where I had to go back to looking through the textbook and a few glances at my first program,
before I got it running properly. I made the usual noob mistakes - since I've tackled many different languages, I had to figure out if I needed to declare variables.
I also got the variable on the wrong side of the equals sign, then I forgot to include commas in my print statement for the variables. I also forgot to state that the variable was an integer. Finally, I forgot to use brackets and then incorrectly included the calculation inside the brackets.
Eventually, I figured all of this out and came up with the above seemingly simple program.
And it works! I'm still not using comments, but I'll fix that when I start writing longer programs.

## an early coding exercise 1

carPrice = input ("what is the base price of the car?") tax = int (carPrice) * .125
insurance = 250
totalcarPrice = int (carPrice) + int (insurance) + int (tax) print ("total cost of your car including: insurance $",insurance,",") print ("and tax:$",tax," comes to $",totalcarPrice) input () This is a program that figures out all your extra costs, when buying a car. The only mistake I still need to figure out, is what the escape clause is for avoiding having a space at the end of a statement inside a print function. It works fine, the user enters the base cost for the car. Program calculates the tax and adds a previously decided insurance cost. Then the program provides the user with both the individual costs, and the total all-inclusive price of the car. EDIT: After some research not in-book, it turns out that you can avoid the white spaces in between statements by using the function sep = "", which should be treated as a variable - so not inside the quotation marks of the print function, rather, naked inside the brackets. So the final program now looks like this: carPrice = input ("what is the base price of the car?") tax = int (carPrice) * .125 insurance = 250 totalcarPrice = int (carPrice) + int (insurance) + int (tax) print ("total cost of your car including: insurance$",insurance,",", sep = "")
print ("and tax: $",tax," comes to$",totalcarPrice, sep = "")   input ()

So it took one day to write and bug fix. Then another day to go through guesswork and figuring it out - to get the program to work. I haven't got up to while loops in the book, so it took a while - a few errors before I got it working. And I certainly haven't got as far as def methods, so using them was difficult and problematic. But I wanted my program to be complete with an exit option.   import random

def end_game():
end_message = ("game over")
print (end_message)

def game():
againPlay = "y"
while againPlay == "y":
print ("you are going to die someday")
againPlay = input ("Still hungry")
print ("you just ate a cookie")
againPlay = input ("Still hungry")
print ("you are going to eat another cookie")
againPlay = input ("Still hungry")
againPlay = input ("Still hungry")
print ("you will have a gargantuan legacy")
againPlay = input ("Still hungry")
else: end_game()
game ()
end_game ()