Python
Python is the best programming language ever C:
It's simple easy, and really useful :)
For a full documentation on how to learn python
google "Python Scripting Tutorial" c:
Miniscripts
My infinite pi generator
from __future__ import print_function
def make_pi():
q, r, t, k, m, x = 1, 0, 1, 1, 3, 3
while (1):
if 4 * q + r - t < m * t:
yield m
q, r, t, k, m, x = 10*q, 10*(r-m*t), t, k, (10*(3*q+r))//t - 10*m, x
else:
q, r, t, k, m, x = q*k, (2*q+r)*x, t*x, k+1, (q*(7*k+2)+r*x)//(t*x), x+2
digits = make_pi()
pi_list = []
my_array = []
for digit in make_pi():
print(digit, end='')
my pyfighter script
#PyFighter 4.0 Alpha
#By Brian Smith
#Idea by Ottosparks
#No rights are reserved
#TIME TO CODE!
import os, math, random
#Variables!
monsterlist = {"0": "Death",
"1": "Brian Smith",
"2": "Ottosparks",
"3": "Badspot",
"4": "Giant",
"5": "Goblin",
"6": "Wizard",
}
monsterhealth = {"Death": 4000,
"Brian Smith": 9001,
"Ottosparks": 400,
"Badspot": 2000,
"Giant": 3000,
"Goblin": 750,
"Wizard": 900,
}
attacklist = {"1": "Slice",
"2": "Stab",
"3": "Thrash",
"4": "Cut",
}
attackdamage = {"Slice": 20,
"Stab": 40,
"Thrash": 10,
"Cut": 5,
}
debugmode = 0
level = 1
monsterHP = 0
currentHP = 100
gold = 100
######################
# Monsters #
######################
def debugMonsters():
for i in range(0,10):
print monsterlist[str(i)]
else:
print "Monster Debug Complete"
def monsterAppear(name):
global potion, gold, monsterHP, currentHP, monsterlist, health, level, monsterhealth, attackdamage
health = monsterhealth[name]
monsterHP = health
print "-----------------------"
print "A Monster has Appeared!"
print "-----------------------"
print "A " + name + " has appeared with " + str(health) + " HP!"
print "Which option do you want to use? Type one of the following:"
print "1 - Attack | 2 - Defend | 3 - Heal | 4 - Use Potion"
input = str(raw_input("Command - "))
if input == "1":
oldMonsterHP = monsterHP
attackMethod = attackMethodRequest()
currentHP,monsterHP = attackMonster(currentHP,monsterHP,attackdamage[attackMethod])
damage = oldMonsterHP - monsterHP
if currentHP < 1:
print "You have died. The game now closes."
return quitGame()
elif monsterHP < 1:
level = level + 1
gold = gold + random.randint(1,100)
print "You have killed the monster, you have also leveled up to level " + str(level) + ". \nYou also obtained gold. You now have " + str(gold) + " gold."
displayOptions()
else:
print "Your attack did " + str(damage) + " damage, and the " + name + "\'s health is now " + str(monsterHP) + " and yours is " + str(currentHP) + " "
nextMove(name)
elif input == "2":
coin = random.randint(0,3)
if coin == 1:
damage = random.randint(1,50)
print "Your dodge failed and you were damaged " + str(damage) + " HP"
currentHP = currentHP - damage
if currentHP < 1:
print "You have died. The game now closes."
return quitGame()
else:
print "You dodged the " + name + "\'s attack!"
nextMove(name)
elif input == "3":
coin = random.randint(0,1)
if coin == 1:
heal = random.randint(15,50)
currentHP = currentHP + heal
print "You heal yourself " + str(heal) + " HP, with " + str(currentHP) + " HP now!"
nextMove(name)
else:
damage = random.randint(50,100)
print "Your heal was interrupted by an attack! You were damaged " + str(damage) + " HP"
currentHP = currentHP - damage
if currentHP < 1:
print "You have died. The game now closes."
return quitGame()
nextMove(name)
elif input == "4":
if potion < 1:
print "You have no potions richardhead."
nextMove(name)
else:
potion = potion - 1
currentHP = currentHP + 100
print "Your health is now " + str(currentHP) + " and you have " + str(potion) + " potions."
nextMove(name)
else:
print "You had to type 1 2 or 3"
print "Clearly since you cant do that, you can't play"
return quitGame()
def attackMethodRequest():
print "Select a Method of Attacking:"
print "1 - Slice | 2 - Stab | Thrash - 3 | Cut - 4"
method = raw_input("Method - ")
if method == 1:
return "Slice"
elif method == 2:
return "Stab"
elif method == 3:
return "Thrash"
elif method == 4:
return "Cut"
else:
return "Cut"
def quitGame():
exit = 1
while exit > exit + 1:
print "Exit"
return exit
def attackMonster(yourHP,otherHP,attackDamage):
global level, armor, armorStats
AM = random.randint(100,1000)
attack = level * attackDamage + AM
attack = otherHP - attack
damage = yourHP - random.randint(15,70) + armorStats[armor]
return damage,attack
def nextMove(name):
global monsterHP, currentHP, level, attackmethod, gold, potion
print "Which option do you want to use? Type one of the following:"
print "1 - Attack | 2 - Defend | 3 - Heal | 4 - Use Potion"
input = str(raw_input("Command - "))
if input == "1":
oldMonsterHP = monsterHP
attackMethod = attackMethodRequest()
currentHP,monsterHP = attackMonster(currentHP,monsterHP,attackdamage[attackMethod])
damage = oldMonsterHP - monsterHP
if currentHP < 1:
print "You have died. The game now closes."
return quitGame()
elif monsterHP < 1:
level = level + 1
gold = gold + random.randint(1,100)
print "You have killed the monster, you have also leveled up to level " + str(level) + ". \nYou also obtained gold. You now have " + str(gold) + " gold."
displayOptions()
else:
print "Your attack did " + str(damage) + " damage, and the " + name + "\'s health is now " + str(monsterHP) + " and yours is " + str(currentHP) + " "
nextMove(name)
elif input == "2":
coin = random.randint(0,3)
if coin == 1:
damage = random.randint(1,50)
print "Your dodge failed and you were damaged " + str(damage) + " HP"
currentHP = currentHP - damage
if currentHP < 1:
print "You have died. The game now closes."
return quitGame()
else:
print "You dodged the " + name + "\'s attack!"
nextMove(name)
elif input == "3":
coin = random.randint(0,1)
if coin == 1:
heal = random.randint(15,50)
currentHP = currentHP + heal
print "You heal yourself " + str(heal) + " HP, with " + str(currentHP) + " HP now!"
nextMove(name)
else:
damage = random.randint(50,100)
print "Your heal was interrupted by an attack! You were damaged " + str(damage) + " HP"
currentHP = currentHP - damage
if currentHP < 1:
print "You have died. The game now closes."
return quitGame()
nextMove(name)
elif input == "4":
if potion < 1:
print "You have no potions richardhead."
nextMove(name)
else:
potion = potion - 1
currentHP = currentHP + 100
print "Your health is now " + str(currentHP) + " and you have " + str(potion) + " potions."
nextMove(name)
else:
print "You had to type 1 2 or 3"
print "Clearly since you cant do that, you can't play"
return quitGame()
######################
#Run the Game #
######################
def startGame():
setLocation("Home")
def randomMonsterAppear():
global monsterlist
monsterAppear(monsterlist[str(random.randint(0,9))])
####################
#Location Stuff #
####################
currentLocation = ""
monsterWatch = 0
monsterPlaces = {"Home": 0,
"Deathly Hollows": 1,
"Bridge": 1,
"Giants Hole": 1,
"Fort Nethgar": 0,
"Firey Cave": 1,
"Woods": 1,
}
deathAttacks = {"Deathly Hollows": 1,
"Firey Cave": 0,
"Woods": 0,
"Bridge": 0,
"Giants Hole": 0,
}
bsAttacks = {"Deathly Hollows": 1,
"Firey Cave": 1,
"Woods": 0,
"Bridge": 0,
"Giants Hole": 0,
}
ottoAttacks = {"Woods": 1,
"Bridge": 1,
"Giants Hole": 0,
"Firey Cave": 0,
"Deathly Hollows": 0,
}
badAttacks = {"Deathly Hollows": 1,
"Giants Hole": 1,
"Woods": 1,
"Bridge": 0,
"Firey Cave": 0,
}
wizAttacks = {"Woods": 1,
"Bridge": 1,
"Firey Cave": 1,
"Deathly Hollows": 0,
"Giants Hole": 0,
}
giantAttacks = {"Woods": 1,
"Bridge": 1,
"Giants Hole": 1,
"Deathly Hollows": 0,
"Firey Cave": 0,
}
gobAttacks = {"Woods": 1,
"Bridge": 1,
"Giants Hole": 1,
"Firey Cave": 1,
"Deathly Hollows": 0,
}
attackArray = {"Death": deathAttacks,
"Brian Smith": bsAttacks,
"Ottosparks": ottoAttacks,
"Badspot": badAttacks,
"Wizard": wizAttacks,
"Giant": giantAttacks,
"Goblin": gobAttacks,
}
locationOptions = {"Home": "Bridge \nFort Nethgar",
"Deathly Hollows": "Firey Cave \nFirey Cave",
"Bridge": "Giants Hole \nFirey Cave",
"Giants Hole": "Bridge \nWoods",
"Fort Nethgar": "Home \nWoods",
"Firey Cave": "Deathly Hollows \nBridge",
"Woods": "Fort Nethgar \nGiants Hole"
}
def setLocation(location):
location = location.strip()
global monsterlist, currentLocation, monsterPlaces, monsterWatch, deathAttacks, bsAttacks, ottoAttacks, badAttacks, giantAttacks, gobAttacks, attackArray
if monsterPlaces[location] == 1:
monsterWatch = 1
else:
monsterWatch = 0
currentLocation = location
print "You are now in " + location + " "
if monsterWatch == 0:
print "Watch out for monsters!"
displayOptions()
else:
coin = random.randint(0,2)
if coin == 1:
print "oh stuff..."
monster = monsterFromLocation(location)
#print monster
monsterAppear(monster)
else:
print "You got lucky, no monsters appear"
displayOptions()
def monsterFromLocation(location):
location = location.strip()
global monsterlist, currentLocation, monsterPlaces, monsterWatch, deathAttacks, bsAttacks, ottoAttacks, badAttacks, giantAttacks, gobAttacks, attackArray
num = random.randint(0,6)
monster = monsterlist[str(num)]
attarray = attackArray[monster]
#print attarray
if attarray[location] == 0:
return monsterFromLocation(location)
else:
#print monster
return monster
def displayOptions():
global currentLocation, currentHP, level, locationOptions, gold
print "------------------------"
print "Your stats:"
print "HP: " + str(currentHP) + " "
print "Level: " + str(level) + " "
print "Location: " + currentLocation + " "
print "Gold: " + str(gold) + " "
if currentLocation == "Fort Nethgar":
print "------------------------"
print "Would you like to buy something?"
print "Type Y/N"
yn = raw_input("Answer - ")
if yn == "":
yn = "N"
if yn.upper() == "Y":
market()
options = locationOptions[currentLocation]
list = options.split("\n")
print "------------------------"
print "Where to go:"
print "1 - " + list[0] + " | 2 - " + list[1] + " "
print "Type the number of the place you would like to visit"
input = int(raw_input("Location - "))
if input == 1:
setLocation(list[0])
elif input == 2:
setLocation(list[1])
else:
setLocation(list[0])
def market():
global gold, currentHP, potion
print "---------------------------"
print "What would you like to buy?"
print "You have " + str(gold) + " gold."
print "---------------------------"
print "1 - Armor | 2 - Potions | 3 - Health | 4 - Quit"
input = raw_input("Buy - ")
input = str(input)
if input == "1":
buyArmor()
elif input == "2":
print "Type in the amount of potions you would like to purchase (100g each):"
input = raw_input("Amount - ")
cost = int(input) * int(100)
if gold < cost:
print "You need " + str(cost) + " gold."
else:
potion = int(potion) + int(input)
print "You have bought " + str(input) + " potions. You have " + str(potion) + " potions."
gold = gold - cost
elif input == "3":
if gold > 50:
gold = gold - 50
currentHP = 100
print "You are healed."
else:
print "You need 50 gold for this."
elif input == "4":
print "You will go back to locations..."
else:
print "You will go back to locations..."
armorStr = {"0": "None",
"1": "Weak",
"2": "Medium",
"3": "Strong",
}
armorStats = {"0": 0,
"1": 35,
"2": 50,
"3": 75,
}
armor = str(0)
potion = 0
def buyArmor():
global gold, armor, armorStr, potion
print "---------------------------"
print "What armor do you want?"
print "1 - Weak | 2 - Medium | 3 - Strong"
print "---------------------------"
input = raw_input("Armor - ")
input = str(input)
if input == "1":
if gold < 100:
print "You need atleast 100 gold for this."
else:
gold = gold - 100
print "You now have " + str(gold) + " gold"
print "and your armor is " + armorStr[input] + " "
armor = input
elif input == "2":
if gold < 200:
print "You need atleast 200 gold for this."
else:
gold = gold - 200
print "You now have " + str(gold) + " gold"
print "and your armor is " + armorStr[input] + " "
armor = input
elif input == "3":
if gold < 300:
print "You need atleast 300 gold for this."
else:
gold = gold - 300
print "You now have " + str(gold) + " gold"
print "and your armor is " + armorStr[input] + " "
armor = input
startGame()
also the above codes are pretty old.
I just need to keep track of my python programs more lol. THose are the only ones i can find :s
talk about python 'n' stuff here.