Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- @version 7/24/2014
- Programming Contest 2
- '''
- import os.path, sys, time
- from datetime import datetime
- def bank(companyName,money,realCompanyName):
- companyName = companyName.lower()
- companyName = companyName + ".txt"
- bankAccountAmmount = 0.0
- choice = 0
- hue = ""
- if os.path.isfile(companyName):
- print("Hello", realCompanyName,"we found your bank account,",end ="")
- companyNameFile = open(companyName, 'r')
- money = float(companyNameFile.read())
- print(" you currently have $",money ,sep = "")
- companyNameFile.close()
- else:
- print("No account found, the program will automatically create a new account")
- while choice != 1:
- choice = input("Type 'add' to add money to the account, type 'withdraw' to withdraw money from the account, type 'exit' to exit the financial account\n").lower()
- if choice == "add":
- addMoney = float(input("How much funding do you want to add to the account?\n"))
- money += addMoney
- elif choice == "withdraw":
- withdrawMoney = float(input("How much funding do you want to withdraw from the account?\n"))
- money -= withdrawMoney
- elif choice == "exit":
- bankAccountAmmount = str(money)
- companyNameFile = open(companyName,'w')
- companyNameFile.write(bankAccountAmmount)
- companyNameFile.close()
- choice = 1
- print("You now have $", money , sep="")
- def file_len(fname):
- with open(fname) as f:
- for i, l in enumerate(f):
- pass
- return i + 1
- def cool(companyName,realTime):
- dic = {}
- wishListUser = companyName + "_finantial_history.txt"
- if os.path.isfile(wishListUser):
- wishListUserFile = open(wishListUser, 'r')
- for line in wishListUserFile:
- hue1 = line.split()
- dic[hue1[0]] = hue1[1]
- #print(dic)
- else:
- item = str(input("Finantial History not found. Creating a new one ...\nWhat item do you want to add to the financial history? (Use space to separate items)\n"))
- count = 0
- items = item.split()
- prices = input("How much did each item cost? (Please enter in order)\n").split()
- for i in range(len(items)):
- count = count + 1
- dic[items[i]] = prices[i]
- wishListUserFile = open(wishListUser, 'w')
- for itemName in dic:
- #wishListUserFile.write(itemName + "\t\t\t" + dic[itemName] + "\n")
- wishListUserFile.write(itemName + "\t\t" + dic[itemName] + "\t\t" + realTime + "\n")
- ###########################################
- wishListUserFile = open(wishListUser, 'r')
- Lines = int(file_len(wishListUser))
- print()
- print("Item\t\tPrice\t\tDate")
- print()
- for i in range(Lines):
- wishListFirstLine = wishListUserFile.readline()
- print(wishListFirstLine)
- print("---------------------------------------------\n")
- ###########################################
- question = input("Do you want to add any items to the financial history?\n").lower()
- if question == "yes":
- item = str(input("What item do you want to add to the financial history? (Use space to separate items)\n"))
- count = 0
- items = item.split()
- prices = input("How much did each item cost? (Please enter in order)\n").split()
- for i in range(len(items)):
- count = count + 1
- dic[items[i]] = prices[i]
- wishListUserFile = open(wishListUser, 'w')
- for itemName in dic:
- wishListUserFile.write(itemName + "\t\t" + dic[itemName] + "\t\t" + realTime + "\n")
- wishListUserFile.close()
- wishListUserFile = open(wishListUser, 'r')
- #wishListFirstLine = wishListUserFile.readline()
- Lines = int(file_len(wishListUser))
- print()
- #for key in sorted(dic):
- #print ("%s\t\t%s\t\t" %(key, dic[key]))
- #Print in alphabetical order with no date
- print("Item\t\tPrice\t\tDate")
- print()
- for i in range(Lines):
- wishListFirstLine = wishListUserFile.readline()
- print(wishListFirstLine)
- print("---------------------------------------------\n")
- else:
- main()
- def saving():
- price = int(input("How many square footage is the new house going to be?\n"))
- floor = int(input("How many floors will it have?\n"))
- quality = int(input("What quality is the house going to be from 1 - 5?\n"))
- if quality == "1":
- quality = 10
- elif quality == "2":
- quality = 20
- elif quality == "3":
- quality = 30
- elif quality == "4":
- quality = 40
- else:
- quality = 50
- calc = price + (price/2) * quality * floor
- print("It wil cost $%d to build the new house." %calc)
- def soup():
- people = int(input("How many people are you expecting to serve?\n"))
- value = 0
- whilebool = True
- while whilebool:
- content = str(input("Would you like to serve Soup, Bread, or Salad? Or would you like to serve a combination of food items?\n")).lower()
- if content == "soup":
- value = 0.5
- break
- elif content == "bread":
- value = 0.7
- break
- elif content == "salad":
- value = 0.3
- break
- elif content == "soup and bread":
- value = 1.2
- break
- elif content == "soup and salad":
- value = 0.8
- break
- elif content == "bread and soup":
- value = 1.2
- break
- elif content == "bread and salad":
- value = 1.0
- break
- elif content == "salad and soup":
- value = 0.8
- break
- elif content == "salad and bread":
- value = 1.0
- break
- elif "salad" and "bread" and "soup" in content:
- value = 1.5
- break
- elif content == "soup bread":
- value = 1.2
- break
- elif content == "soup salad":
- value = 0.8
- break
- elif content == "bread soup":
- value = 1.2
- break
- elif content == "bread salad":
- value = 1.0
- break
- elif content == "salad soup":
- value = 0.8
- break
- elif content == "salad bread":
- value = 1.0
- break
- else:
- print("Please input Soup, Bread or Salad")
- calc = value * people
- print("It will cost", calc, "to serve", content, "at your soup kitchen.")
- def main():
- print('''
- ██╗ ██╗ ███████╗ ██╗ ██╗
- ██║ ██║ ██╔════╝ ██║ ██║
- ███████║ █████╗ ███████║
- ██╔══██║ ██╔══╝ ██╔══██║
- ██║ ██║██╗██║ ██╗██║ ██║
- ╚═╝ ╚═╝╚═╝╚═╝ ╚═╝╚═╝ ╚═╝
- Habitat for Humanity management program.
- Copyright © 2014 KAB Studios. All Rights Reserved. ''')
- #companyName = input("What is your company name?\n")
- companyName = "Habitat for Humanity"
- print()
- print("Wecome to the %s money management" %companyName)
- unixTime = time.time()
- #print(unixTime)
- realTime = datetime.fromtimestamp(unixTime).strftime('%Y-%m-%d')
- #print(realTime)
- money = 0.0
- realCompanyName = companyName
- hue0 = str(input("From what part of %s are you from?\n" %companyName))
- while True:
- checkBank = input("Do you want to access the financial acount?\n").lower()
- if checkBank == "yes":
- bank(companyName,money,realCompanyName)
- break
- elif checkBank == "no":
- break
- else:
- print("Please input Yes or No")
- while True:
- hue3 = input("Do you want to check the financial history?\n").lower()
- if hue3 == "yes":
- cool(companyName, realTime)
- elif hue3 == "no":
- break
- else:
- print("Please input Yes or No")
- while True:
- hue4 = input("Do you want to calculate the price to build a new home?\n").lower()
- if hue4 == "yes":
- saving()
- break
- elif hue4 == "no":
- break
- else:
- print("Please input Yes or No")
- while True:
- hue6 = input("Do you want to calculate how much money it would take to host a soup kitchen?\n").lower()
- if hue6 == "yes":
- soup()
- break
- elif hue6 == "no":
- break
- else:
- print("Please input Yes or No")
- hue5 = input("Do you want to restart the program?\n").lower()
- if hue5 == "yes":
- main()
- else:
- print("Thank you for using KAB programs! Goodbye!")
- try:
- main()
- except ValueError as e:
- print("Oops! That was not a valid number.")
- except Exception as e:
- print(e)
- finally:
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement