Discuss Scratch

jackkillian
Scratcher
24 posts

Python Projects

Do code Python? Share your projects here!

Last edited by jackkillian on March 9, 9999
#Bring_it_Back
Hi, and welcome to Scratch! Click Here to go to the Scratch home page.
jackkillian
Scratcher
24 posts

Python Projects

Password Creator V 1.0
Make sure you Python 3 installed
Make a new file and paste the following code into it.
Save it as ‘Password Creator V 1.0.py’.
Here's the code:

colors =
adjectives =
animals =

import random
import pip
try:
import pyperclip as ppc
installed = ‘yes’
except:
print('Pyperclip not installed. If you would like to copy the password to the clipboard, please install it.')
install = input('Would you like to install Pyperclip? ‘)
if install == ’y':
pip.main()
installed = ‘y’
else:
installed = ‘no’

new = ‘y’

while new == ‘y’:
print('Creating your new password…')
new_adj = random.choice(adj)
new_ani = random.choice(ani)
password = new_adj + new_ani + color + str(random.randint(0, 1000))
print('Your new password is:')
print(password)
if installed == ‘yes’:
copy = input('Would you like to copy password to clipboard? ‘)
if copy ==’y':
ppc.copy(password)
print('Copied.')
new = input('Would you like to make a new password? ')

Last edited by jackkillian on March 9, 9999
#Bring_it_Back
Hi, and welcome to Scratch! Click Here to go to the Scratch home page.
jackkillian
Scratcher
24 posts

Python Projects

Sorry, on Password Creator V 1.0:
color =
adjectives =
animals =
it is supposed to be:


And where it says ‘pip.main()’ is is supposed to be:


Sorry!

Last edited by jackkillian (March 8, 2018 21:09:23)


Last edited by jackkillian on March 9, 9999
#Bring_it_Back
Hi, and welcome to Scratch! Click Here to go to the Scratch home page.
SuperSonicmario
Scratcher
100+ posts

Python Projects

Base64 encoder.
def b64encode(x):
t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
x = "".join(["0"*(8-len(bin(ord(i))[2:]))+bin(ord(i))[2:] for i in x])
o = ""
for i in [x[c:c+6] for c in range(0,len(x),6)]:
o += t[int(i+"0"*(6-len(i)),2)]+"="*((6-len(i))//2)
return o

Wow, ST! Why is the new design so good now?! And it's not just me getting accustomed, I saw changes!
asqwde
Scratcher
1000+ posts

Python Projects

Is there like a online site where you can publish python projects like you can do scratch projects?
jackkillian
Scratcher
24 posts

Python Projects

asqwde wrote:

Is there like a online site where you can publish python projects like you can do scratch projects?
I don't know. I hope there is. Maybe Google it.

Last edited by jackkillian on March 9, 9999
#Bring_it_Back
Hi, and welcome to Scratch! Click Here to go to the Scratch home page.
DaEpikDude
Scratcher
1000+ posts

Python Projects

this one is pretty big

it's a game thing i made

from sys import exit
from time import sleep

areas = {
1:{"type": "mountain"},
2:{"type": "plains"},
3:{"type": "forest"},
4:{"type": "lake"}}

materialtypes = {
"1":"wood",
"2":"stone",
"3":"food",
"4":"water"}

buildtypes = {
"1":"hut",
"2":"house",
"3":"shed",
"4":"farm",
"5":"cabin",
"6":"mine",
"7":"well",
"8":"ship"}

builds = {}

boost = 0

buildnums = {
"hut":0, "house":0, "shed":0, "mine":0, "farm":0, "cabin":0, "well":0, "ship":0}

types = {
"mountain": {
"resources": ["stone", "water"],
"traversal": "hard",
"buildqual": "hard",
"desc": "Mountains are hard to work on, but provide lots of stone."},
"plains": {
"resources": ["food", "wood"],
"traversal": "easy",
"buildqual": "easy",
"desc": "Plains are plentiful in food, and are good to build on."},
"forest": {
"resources": ["wood", "stone"],
"traversal": "easy",
"buildqual": "hard",
"desc": "Forests give lots of wood, but they're hard to build on."},
"lake": {
"resources": ["water", "food"],
"traversal": "hard",
"buildqual": "easy",
"desc": "Lakes give plenty of water, but can be hard to get around."}
}

chars = {
1: {"name": "Andrew",
"str": 5,
"stam": 6,
"plan": 4,
"happ": 10,
"nrg": 50,
"hung": 0,
"thirst": 0,
"awake": 15,
"task": {"area": "none", "job": "none"}},
2: {"name": "Beth",
"str": 3,
"stam": 2,
"plan": 9,
"happ": 10,
"nrg": 50,
"hung": 0,
"thirst": 0,
"awake": 15,
"task": {"area": "none", "job": "none"}},
3: {"name": "Charles",
"str": 9,
"stam": 8,
"plan": 1,
"happ": 10,
"nrg": 50,
"hung": 0,
"thirst": 0,
"awake": 15,
"task": {"area": "none", "job": "none"}},
4: {"name": "David",
"str": 8,
"stam": 2,
"plan": 6,
"happ": 10,
"nrg": 50,
"hung": 0,
"thirst": 0,
"awake": 15,
"task": {"area": "none", "job": "none"}}
}

resourc = {"wood":0, "stone":0, "water":0, "food":0}

buildings = {
"hut":15,
"house":25,
"shed":25,
"mine":40,
"farm":35,
"well": 30,
"cabin":30,
"ship":100}

def removekey(d, key):
r = dict(d)
del r[key]
return r

def set_task(area, job, person):
chars[person]["task"]["job"] = job
chars[person]["task"]["area"] = area

def cont_tasks():
global boost, builds, buildnums, resourc, buildings, chars, types, areas
for i in chars:
if chars[i]["task"]["job"] == "none":
chars[i]["nrg"] += 1 + (buildnums["hut"] + (buildnums["house"] * 2)) * 2
if chars[i]["nrg"] > 50:
chars[i]["nrg"] = 50
chars[i]["happ"] += 1 + buildnums["hut"] + (buildnums["house"] * 2)
if chars[i]["happ"] >= 20:
chars[i]["happ"] = 20
chars[i]["awake"] += 2
if chars[i]["awake"] >= 15:
chars[i]["awake"] = 15
else:
if chars[i]["nrg"] - (10 - chars[i]["stam"]) <= 0:
print("%s is exhausted..." % chars[i]["name"])
else:
if chars[i]["task"]["job"] not in buildings:
if chars[i]["task"]["job"] == "wood":
boost = buildnums["cabin"] * 2
elif chars[i]["task"]["job"] == "stone":
boost = buildnums["mine"] * 2
elif chars[i]["task"]["job"] == "food":
boost = buildnums["farm"] * 2
else:
boost = buildnums["well"] * 2
if types[areas[chars[i]["task"]["area"]]["type"]]["resources"][0] == chars[i]["task"]["job"]:
resourc[chars[i]["task"]["job"]] += (chars[i]["str"] // 2) + 3 + boost
print("%s collected lots of %s!" % (chars[i]["name"], chars[i]["task"]["job"]))
elif types[areas[chars[i]["task"]["area"]]["type"]]["resources"][1] == chars[i]["task"]["job"]:
resourc[chars[i]["task"]["job"]] += 3 + (chars[i]["str"] // 4) + 1 + (boost / 2)
("%s collected some %s!" % (chars[i]["name"], chars[i]["task"]["job"]))
else:
resourc[chars[i]["task"]["job"]] += boost / 4
("%s collected a bit of %s." % (chars[i]["name"], chars[i]["task"]["job"]))
if types[areas[chars[i]["task"]["area"]]["type"]]["traversal"] == "hard":
chars[i]["nrg"] -= 10 - chars[i]["stam"]
chars[i]["happ"] -= 2
else:
chars[i]["nrg"] -= (10 - chars[i]["stam"]) // 2
chars[i]["happ"] -= 1
else:
if chars[i]["task"]["job"] not in builds:
builds[chars[i]["task"]["job"]] = 0
print ("%s started to build a %s!" % (chars[i]["name"], chars[i]["task"]["job"]))
elif types[areas[chars[i]["task"]["area"]]["type"]]["buildqual"] == "easy":
if resourc["wood"] - chars[i]["plan"] < 0 or resourc["stone"] - (chars[i]["plan"] / 2) < 0:
print ("%s didn't have enough materials to keep building the %s!" % (chars[i]["name"], chars[i]["task"]["job"]))
else:
builds[chars[i]["task"]["job"]] += chars[i]["plan"]
print ("%s continued building the %s!" % (chars[i]["name"], chars[i]["task"]["job"]))
resourc["wood"] -= chars[i]["plan"]
resourc["stone"] -= chars[i]["plan"] / 2
else:
if resourc["wood"] - (chars[i]["plan"] / 2) < 0 or resourc["stone"] - (chars[i]["plan"] / 4) < 0:
print ("%s didn't have enough materials to keep building the %s!" % (chars[i]["name"], chars[i]["task"]["job"]))
else:
builds[chars[i]["task"]["job"]] += chars[i]["plan"] / 2
print ("%s continued building the %s!" % (chars[i]["name"], chars[i]["task"]["job"]))
resourc["wood"] -= chars[i]["plan"] / 2
resourc["stone"] -= chars[i]["plan"] / 4
if builds[chars[i]["task"]["job"]] >= buildings[chars[i]["task"]["job"]]:
print ("The %s is built!" % chars[i]["task"]["job"])
buildnums[chars[i]["task"]["job"]] += 1
builds = removekey(builds, chars[i]["task"]["job"])
for j in chars:
if chars[j]["task"]["job"] == chars[i]["task"]["job"] and j != i:
chars[j]["task"]["job"] = "none"
chars[j]["task"]["area"] = "none"
chars[i]["task"]["job"] = "none"
chars[i]["task"]["area"] = "none"
chars[i]["awake"] -= 1
chars[i]["hung"] += 1
chars[i]["thirst"] += 1
if chars[i]["hung"] >= 10:
print ("%s is starving!!!" % chars[i]["name"])
chars[i]["happ"] = 0
chars[i]["nrg"] = 0
elif chars[i]["hung"] >= 7:
print ("%s is starting to feel hungry..." % chars[i]["name"])
if chars[i]["thirst"] >= 10:
print ("%s is dehydrated!!!" % chars[i]["name"])
elif chars[i]["thirst"] >= 7:
print ("%s is feeling thirsty..." % chars[i]["name"])
if chars[i]["happ"] <= 0:
print ("%s is feeling terrible..." % chars[i]["name"])
chars[i]["nrg"] -= 15
if chars[i]["nrg"] <= 0:
chars[i]["nrg"] = 0
elif chars[i]["happ"] <= 3:
print ("%s feeling pretty bad." % chars[i]["name"])
if chars[i]["awake"] == 0:
print ("%s fell asleep on the spot!!!" % chars[i]["name"])
chars[i]["nrg"] = 0
chars[i]["happ"] = 1
chars[i]["task"]["job"] = "none"
chars[i]["task"]["area"] = "none"
elif chars[i]["awake"] <= 3:
print ("%s is feeling VERY tired..." % chars[i]["name"])
elif chars[i]["awake"] <= 5:
print ("%s is pretty tired..." % chars[i]["name"])
for j in resourc:
if resourc[j] >= (buildnums["shed"] + 1) * 20:
print ("The group is full on %s!" % j)
resourc[j] = (buildnums["shed"] + 1) * 20

def eat():
if resourc["food"] >= 8:
resourc["food"] -= 8
print("Everyone ate some food!")
for i in chars:
chars[i]["hung"] = 0
chars[i]["happ"] += 2
if chars[i]["happ"] > 20:
chars[i]["happ"] = 20
else:
print("There isn't enough food to feed everyone!")

def drink():
if resourc["water"] >= 8:
print("Everyone drank some water!")
resourc["water"] -= 8
for i in chars:
chars[i]["thirst"] = 0
chars[i]["happ"] += 2
if chars[i]["happ"] > 20:
chars[i]["happ"] = 20
else:
print ("There isn't enough water for everyone to drink!")

def check_builds():
for i in buildnums:
if buildnums[i] == 1:
print ("There is one %s built." % i)
else:
print ("There are %d %ss built." % (buildnums[i], i))

print ("Andrew, Beth, Charles and David are shipwrecked!")
while True:
done = 0
print ("Actions:\n1: Set task: Tell group members what to do.\n2: Cancel all tasks: Stops all current tasks.\n3: View terrain info: Shows info about the different terrain types.\n4: View character statistics: Show strengths & weaknesses of the characters.\n5: Eat & drink: Reset hunger & thirst with food & water.\n6: View resources: List how many of each resource you have.\n7: View building info: Shows perks of different buildings.\n8: View building numbers: See how many of each building you have built.\n9: Skip time forwards: Do the actions you've assigned!\n0: Set sail: Set sail with a ship!!")
action = input("Choose an action: ")
if action == "1":
while done == 0:
char = input("Who should do the job?\n1: Andrew, 2: Beth, 3: Charles, 4: David\nChoose one: ")
if char.isdigit():
if int(char) not in chars:
print ("Not a valid selection!")
break
else:
print ("Not a valid selection!")
break
area = input("Where should they work?\n1: Mountain, 2: Plains, 3: Forest, 4: Lake\nChoose one: ")
if area.isdigit():
if int(area) not in areas:
print ("Not a valid selection!")
break
else:
print ("Not a valid selection!")
break
task = input("What should they do?\n1: Collect materials, 2: Build something\nChoose one: ")
if task.isdigit():
if int(task) not in range(1, 3):
print ("Not a valid selection!")
break
else:
print ("Not a valid selection!")
break
if task == "1":
selec = input("What to collect? (view terrain info for what has what)\n1: wood, 2: stone, 3: food, 4: water\nChoose one: ")
if selec in materialtypes:
set_task(int(area), materialtypes[selec], int(char))
done = 1
else:
print ("Not a valid selection!")
elif task == "2":
selec = input("What to build?\n1: hut, 2: house, 3: shed, 4: farm, 5: cabin, 6: mine, 7: well, 8: ship\nChoose one: ")
if selec in buildtypes:
set_task(int(area), buildtypes[selec], int(char))
done = 1
else:
print ("Not a valid selection!")
break
elif action == "2":
for i in chars:
set_task("none", "none", i)
elif action == "3":
for i in types:
print ("%s: %s" % (i, types[i]["desc"]))
elif action == "4":
select = input("1: Andrew, 2: Beth, 3: Charles, 4: David\nSelect one: ")
if select.isdigit():
try:
print("Strength: %d. Strength increases yield from gathering." % chars[int(select)]["str"])
print("Stamina: %d. Stamina decreases energy uses." % chars[int(select)]["stam"])
print("Planning: %d. Planning speeds up building construction." % chars[int(select)]["plan"])
print("Morale: %d. Low morale increases energy use." % chars[int(select)]["happ"])
print("Awakeness: %d/15. Instant 0 energy if you run out." % chars[int(select)]["awake"])
print("Hunger: %d/10. Eat to reset!" % chars[int(select)]["hung"])
print("Thirst: %d/10. Drink to reset!" % chars[int(select)]["thirst"])
print("Energy: %d/50. Don't do anything to recover." % chars[int(select)]["nrg"])
except KeyError:
print("Not a valid selection!")
else:
print("Not a valid selection!")
elif action == "5":
eat()
drink()
elif action == "6":
for i in resourc:
print ("%s: %d" % (i, resourc[i]))
elif action == "7":
print("Hut: Provides bonus to energy regen.\nHouse: Provides large bonus to energy regen.\nShed: Increases resource storage.\nFarm: When gathering food, you get more.\nMine: When gathering stone, you get more.\nCabin: When gathering wood, you get more.\nWell: When gathering water, you get more.\nShip: Takes tons of resources to make. Escape the island!")
elif action == "8":
check_builds()
elif action == "9":
cont_tasks()
elif action == "0":
if buildnums["ship"] >= 1:
if resourc["food"] >= 50 and resourc["water"] >= 50:
print ("The group set sail!!!")
sleep (1)
print ("You managed to escape the island!")
sleep(0.5)
print ("You win!!!")
exit()
else:
print ("You need at least 50 food and 50 water to set sail.")
else:
print ("How do you expect to set sail without a ship?")
elif action == "exit":
exit()
else:
print("Not a valid action!")
out = 0
for i in chars:
if chars[i]["hung"] == 10 or chars[i]["thirst"] == 10:
out += 1
if out == 4:
if resourc["food"] < 8 or resourc["water"] < 8:
print ("The group is out of supplies...", end = "")
sleep(1)
for i in range(5):
print("...", end = "")
sleep(1)
print ("\nYou failed...")
exit()

“bah humbug” - scrooge
jackkillian
Scratcher
24 posts

Python Projects

DaEpikDude wrote:

this one is pretty big

it's a game thing i made

(code)
Cool!

Last edited by jackkillian on March 9, 9999
#Bring_it_Back
Hi, and welcome to Scratch! Click Here to go to the Scratch home page.
MissingFlight370
Scratcher
9 posts

Python Projects

I coded python but didn't like it.

don't ask

Powered by DjangoBB

Standard | Mobile