⌘ python scripts

this language is weird

Page last updated: Mar 25 2019

Car Inventory Data

#! /usr/bin/env python3
# Justin Scofield
# CIS 299 300
# Program 4

# inventoryList =  [Model, MSRP, Cars in Inventory]

car1 = ["Chevy Bolt EV",37495,2]
car2 = ["Kia Niro",24485,23]
car3 = ["VW e-Golf",32790,12]
car4 = ["Hyundai Kona",37495,3]
car5 = ["Honda Insight",23725,4]
car6 = ["Chevrolet Volt",34395,14]
car7 = ["Hyundai Ioniq",23285,5]
car8 = ["Tesla Model 3",45200,1]
car9 = ["Audi e-tron",75795,2]
car10 = ["Toyota Prius",24405,12]
inventoryList = [car1,car2,car3,car4,car5,car6,car7,car8,car9,car10]

def printCarList(): #iterates over every list in the inventory for amount and model
    print("------------------------------------")
    print("Vehicle Inventory by Type")
    print("Inventory \t\tMake/Model \t\t")
    for each in inventoryList:
        print("\t%d\t\t%s \t\t" % (each[2], each[0]))

def countInventory(): # adds up the inventory amount of each
    print("------------------------------------")
    print("Total Vehicle Stock Count")
    # x being the vehicle amount pulled from inventory list
    product = sum(x[2] for x in inventoryList[0:])
    print("There are %d cars in inventory" % product)

def printInventoryValue(): # takes the sum of the cars value and how many there are and multiplies
    print("------------------------------------")
    print("Total Vehicle Stock Value\n")
    stockprice = sum(z[1] for z in inventoryList[0:])
    stockamt = sum(y[2] for y in inventoryList[0:])
    stockval = stockprice * stockamt
    print("$"+"{:,.2f}".format(stockval)) # formatted for currency commas and change

def printEachCarValue(): # displays price of each car based on how many in stock
    print("------------------------------------")
    print("Vehicle Stock Value by Model\n")
    for every in inventoryList:
        print("%s inventory value = ${:,.2f}".format(every[2]*every[1]) % every[0])

def getHighest(): # takes the highest priced car and displays
    print("------------------------------------")
    print("The vehicle with the highest MSRP:")
    highest = max(inventoryList[0:], key=lambda w: w[1])
    print("%s with an MSRP of ${:,.2f}".format(highest[1]) % highest[0])

def getLowest(): # lowest car, found the lambda thing on stack overflow
    print("------------------------------------")
    print("The vehicle with the lowest MSRP:")
    lowest = min(inventoryList[0:], key=lambda v: v[1])
    print("%s with an MSRP of ${:,.2f}".format(lowest[1]) % lowest[0])

def mainLoop():
        print("Welcome to Eletric Avenue")
        x = "24"
        while x != "0":
            print("\nEnter 1) View All Cars in Inventory")
            print("Enter 2) Get Total Car Count")
            print("Enter 3) Get Total Inventory Value")
            print("Enter 4) Get Inventory Value by Car")
            print("Enter 5) Get Highest Priced Car")
            print("Enter 6) Get Lowest Priced Car")
            print("\nEnter 0 to end")
            x = input("Please make a selection:")
            if x == "1":
                printCarList()
            elif x == "2":
                countInventory()
            elif x == "3":
                printInventoryValue()
            elif x == "4":
                printEachCarValue()
            elif x == "5":
                getHighest()
            elif x == "6":
                getLowest()
            else:
                print("Thank you for using the inventory system.")

mainLoop()

Zeniea Twitter bot

I've decided while I'm taking my Intro to Python course that I'll work on using the Twitter API with Python to control the @zeniea_ account that I used to use to post zQuest updates. I'm working on what I want to do with the bot right now, the code below is only the beginning of the file. I'm looking into the tkinter library just to interface with for the moment. I'll add more to this. However, if you wanted to connect to your Twitter Developer Account, this will print your username. Lol.

#! /usr/bin/env python3
# Justin Scofield
# Feb 3 2019
# Zeniea Twitter Bot

# Adding tweepy for Twitter, Tkinter for personal GUI
import tweepy
from tkinter import *

# Twitter Application Consumer API Key and Access Token
consumer_key = 'express123'
consumer_secret = 'express12345'
access_token = 'AkitronSucks'
access_token_secret = 'AkitronSucksALot'

# Authenticate Twitter account
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)

user = api.me()
print ("Welcome to the bot prompt, %s" % (user.name))
print ()

Inventory Loop Subroutine

#! /usr/bin/env python3
# Justin Scofield
# CIS 299 300
# Program 3

print("Welcome User")
print("\nThis program allows a user to enter items")
print("related to the inventory of a hardware store.")
print("Users will enter: Item Name, Item Quantity and Item Cost.")
print("At the end a summary report is displayed.")
print("New Item: ")

no = ["n", "no", "N", "NO"]
totalQuantity = []
totalCost = []

def inventoryAdd():
    itemName = input("Please enter the item name: ")
    itemQuantity = int(input("Please enter the item quantity: "))
    itemCost = float(input("Please enter the item cost: "))
    totalQuantity.append(itemQuantity)
    totalCost.append(itemCost * itemQuantity)
    inventoryValue = itemQuantity * itemCost
    print("  Summary for this item: ")
    print("    Item Name:       %s" % itemName)
    print("    Total Quantity:  %s" % itemQuantity)
    print("    Item Cost:       $%0.2f" % itemCost)
    print("    Inventory Value: $%0.2f" % inventoryValue)

def finish():
    print("\nThank you\nCalculating totals...")
    print("\nHardware Store Inventory Report")
    print("-------------------------------")
    print("Total Items in Inventory: %g" % sum(totalQuantity))
    print("Total Value of Inventory: $%0.2f" % sum(totalCost))
    return

while True:
    inventoryAdd()
    entry = input("To enter another item press 'y', else press 'n': ")
    if entry in no:
        finish()
        break
    else:
        continue

Rock Paper Scissors

This is the second program I've written in my intro to python class in college. It's pretty autistic looking considering its just a big copy and paste machine. I'm sure there's a better way I could've gone about this but just for starting out the class and getting the hang of the if else statement this is what he wanted us to do.

#! /usr/bin/env python3
# Justin Scofield
# CIS 299 300
# Program 2

# Variables Used
# Defining all the choices, under Input Variables
# player1Choice & player2Choice to get each players input

print("Welcome to Rock Paper Scissors Lizard Spock")
print("Please enter a value for each user using only lowercase letters.")
print()

# Input Variables
rockVar = 'rock'
paperVar = 'paper'
scissorsVar = 'scissors'
lizardVar = 'lizard'
spockVar = 'spock'

# capture player choices
player1Choice = input("Player 1 Choice: 'rock' 'paper' 'scissors' 'lizard' or 'spock': ")
player2Choice = input("Player 2 Choice: 'rock' 'paper' 'scissors' 'lizard' or 'spock': ")

print()
print("Player 1 chose %s" %(player1Choice)) # displaying choices
print("Player 2 chose %s" %(player2Choice))
print()

if player1Choice == player2Choice:
    print("The result of the game is a tie.") #any equal choices result in a tie

elif player1Choice == rockVar:
    if player2Choice == paperVar:
        print("%s covers %s, Player 2 wins." % (paperVar,rockVar))
    elif player2Choice == scissorsVar:
        print("%s crushes %s, Player 1 wins." % (rockVar,scissorsVar))
    elif player2Choice == lizardVar:
        print("%s crushes %s, Player 1 wins." % (rockVar,lizardVar))
    elif player2Choice == spockVar:
        print("%s vaporizes %s, Player 2 wins." % (spockVar,rockVar))

elif player1Choice == paperVar:
    if player2Choice == scissorsVar:
        print("%s cuts %s. Player 2 wins." % (scissorsVar,paperVar))
    elif player2Choice == rockVar:
        print("%s covers %s. Player 1 wins." % (paperVar,rockVar))
    elif player2Choice == lizardVar:
        print("%s eats %s. Player 2 wins." % (lizardVar,paperVar))
    elif player2Choice == spockVar:
        print("%s disproves %s. Player 1 wins." % (paperVar,spockVar))

elif player1Choice == scissorsVar:
    if player2Choice == paperVar:
        print ("%s cuts %s. Player 1 wins." % (scissorsVar,paperVar))
    elif player2Choice == rockVar:
        print ("%s crushes %s. Player 2 wins." % (rockVar,scissorsVar))
    elif player2Choice == lizardVar:
        print ("%s decapitates %s. Player 1 wins." % (scissorsVar,lizardVar))
    elif player2Choice == spockVar:
        print ("%s smashes %s. Player 2 wins." % (spockVar,scissorsVar))

elif player1Choice == lizardVar:
    if player2Choice == scissorsVar:
        print ("%s decapitates %s. Player 2 wins." % (scissorsVar,lizardVar))
    elif player2Choice == rockVar:
        print ("%s crushes %s. Player 2 wins." % (rockVar,lizardVar))
    elif player2Choice == spockVar:
        print ("%s poisons %s. Player 1 wins" % (lizardVar,spockVar))
    elif player2Choice == paperVar:
        print ("%s eats %s. Player 1 wins." % (lizardVar,paperVar))

elif player1Choice == spockVar:
    if player2Choice == scissorsVar:
        print ("%s smashes %s. Player 1 wins." % (spockVar,scissorsVar))
    elif player2Choice == rockVar:
        print ("%s vaporizes %s. Player 1 wins." % (spockVar,rockVar))
    elif player2Choice == lizardVar:
        print ("%s poisons %s. Player 2 wins." (lizardVar,spockVar))
    elif player2Choice == paperVar:
        print ("%s disproves %s. Player 2 wins." (paperVar,spockVar))

else:
    print("Invalid input.")

USD to YEN Conversion

I'm really only putting this here as a formality considering how mundane this script is but I want to have record of the bottom of my abilities lol.

# JUSTIN SCOFIELD
# CIS 299 300
# ASSIGNMENT PROGRAM 1 USD TO YEN CONVERSION

# VARIABLES USED
# USD - THE PROMPTED INPUT FOR THE AMOUNT IN DOLLARS TO BE CONVERTED
# YEN - THE CONVERSION RATE MULTIPLIED BY THE INPUTED DOLLAR AMOUNT

print("Hello, user.") #greet user
print("This program will convert US dollars into yen.") #define the task
print() #print a blank line for aesthetic
usd = float(input('Amount of dollars: '))
#float the input in case of decimal points
yen = usd * 114.62
#multiply the inputted value by the conversion rate
print("Processing...")
print(usd, "U.S. dollars equals", yen , "yen")
#repeat the input, then display the output with text