Advertisement
bha2597

Program contest

Jul 25th, 2014
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.34 KB | None | 0 0
  1. '''
  2. @version 7/24/2014
  3. Programming Contest 2
  4. '''
  5.  
  6. import os.path, sys, time
  7. from datetime import datetime
  8.  
  9. def bank(companyName,money,realCompanyName):
  10.    
  11.     companyName = companyName.lower()
  12.     companyName = companyName + ".txt"
  13.     bankAccountAmmount = 0.0
  14.     choice = 0
  15.     hue = ""
  16.  
  17.     if os.path.isfile(companyName):
  18.         print("Hello", realCompanyName,"we found your bank account,",end ="")
  19.         companyNameFile = open(companyName, 'r')
  20.         money = float(companyNameFile.read())
  21.         print(" you currently have $",money ,sep = "")
  22.         companyNameFile.close()
  23.     else:
  24.         print("No account found, the program will automatically create a new account")
  25.    
  26.  
  27.     while choice != 1:
  28.         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()
  29.         if choice == "add":
  30.             addMoney = float(input("How much funding do you want to add to the account?\n"))
  31.             money += addMoney
  32.  
  33.         elif choice == "withdraw":
  34.             withdrawMoney = float(input("How much funding do you want to withdraw from the account?\n"))
  35.             money -= withdrawMoney
  36.  
  37.         elif choice == "exit":
  38.            
  39.             bankAccountAmmount = str(money)
  40.             companyNameFile = open(companyName,'w')
  41.             companyNameFile.write(bankAccountAmmount)
  42.             companyNameFile.close()
  43.  
  44.            
  45.             choice = 1
  46.        
  47.  
  48.        
  49.    
  50.     print("You now have $", money , sep="")
  51.  
  52. def file_len(fname):
  53.     with open(fname) as f:
  54.         for i, l in enumerate(f):
  55.             pass
  56.     return i + 1
  57.  
  58. def cool(companyName,realTime):
  59.    
  60.     dic = {}
  61.     wishListUser = companyName + "_finantial_history.txt"
  62.    
  63.     if os.path.isfile(wishListUser):
  64.         wishListUserFile = open(wishListUser, 'r')
  65.         for line in wishListUserFile:
  66.             hue1 = line.split()
  67.             dic[hue1[0]] = hue1[1]
  68.         #print(dic)
  69.     else:
  70.         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"))
  71.        
  72.         count = 0
  73.         items = item.split()
  74.         prices = input("How much did each item cost? (Please enter in order)\n").split()
  75.         for i in range(len(items)):
  76.             count = count + 1
  77.             dic[items[i]] = prices[i]
  78.        
  79.         wishListUserFile = open(wishListUser, 'w')
  80.         for itemName in dic:
  81.             #wishListUserFile.write(itemName + "\t\t\t" + dic[itemName] + "\n")
  82.             wishListUserFile.write(itemName + "\t\t" + dic[itemName] + "\t\t" + realTime + "\n")
  83.  
  84.     ###########################################
  85.     wishListUserFile = open(wishListUser, 'r')
  86.     Lines = int(file_len(wishListUser))
  87.     print()
  88.     print("Item\t\tPrice\t\tDate")
  89.     print()
  90.     for i in range(Lines):
  91.         wishListFirstLine = wishListUserFile.readline()
  92.         print(wishListFirstLine)
  93.         print("---------------------------------------------\n")
  94.     ###########################################
  95.     question = input("Do you want to add any items to the financial history?\n").lower()
  96.     if question == "yes":
  97.         item = str(input("What item do you want to add to the financial history? (Use space to separate items)\n"))
  98.        
  99.         count = 0
  100.         items = item.split()
  101.         prices = input("How much did each item cost? (Please enter in order)\n").split()
  102.         for i in range(len(items)):
  103.             count = count + 1
  104.             dic[items[i]] = prices[i]
  105.        
  106.         wishListUserFile = open(wishListUser, 'w')
  107.         for itemName in dic:
  108.             wishListUserFile.write(itemName + "\t\t" + dic[itemName] + "\t\t" + realTime + "\n")
  109.  
  110.         wishListUserFile.close()
  111.         wishListUserFile = open(wishListUser, 'r')
  112.         #wishListFirstLine = wishListUserFile.readline()
  113.         Lines = int(file_len(wishListUser))
  114.         print()
  115.         #for key in sorted(dic):
  116.             #print ("%s\t\t%s\t\t" %(key, dic[key]))
  117.             #Print in alphabetical order with no date
  118.         print("Item\t\tPrice\t\tDate")
  119.         print()
  120.         for i in range(Lines):
  121.             wishListFirstLine = wishListUserFile.readline()
  122.             print(wishListFirstLine)
  123.             print("---------------------------------------------\n")
  124.     else:
  125.         main()
  126. def saving():
  127.     price = int(input("How many square footage is the new house going to be?\n"))
  128.  
  129.     floor = int(input("How many floors will it have?\n"))
  130.  
  131.     quality = int(input("What quality is the house going to be from 1 - 5?\n"))
  132.     if quality == "1":
  133.         quality = 10
  134.     elif quality == "2":
  135.         quality = 20
  136.     elif quality == "3":
  137.         quality = 30
  138.     elif quality == "4":
  139.         quality = 40
  140.     else:
  141.         quality = 50
  142.  
  143.     calc = price + (price/2) * quality * floor
  144.  
  145.     print("It wil cost $%d to build the new house." %calc)
  146.    
  147. def soup():
  148.     people = int(input("How many people are you expecting to serve?\n"))
  149.     value = 0
  150.     whilebool = True
  151.  
  152.     while whilebool:
  153.         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()
  154.         if content == "soup":
  155.             value = 0.5
  156.             break
  157.         elif content == "bread":
  158.             value = 0.7
  159.             break
  160.         elif content == "salad":
  161.             value = 0.3
  162.             break
  163.         elif content == "soup and bread":
  164.             value = 1.2
  165.             break
  166.         elif content == "soup and salad":
  167.             value = 0.8
  168.             break
  169.         elif content == "bread and soup":
  170.             value = 1.2
  171.             break
  172.         elif content == "bread and salad":
  173.             value = 1.0
  174.             break
  175.         elif content == "salad and soup":
  176.             value = 0.8
  177.             break
  178.         elif content == "salad and bread":
  179.             value = 1.0
  180.             break
  181.         elif "salad" and "bread" and "soup" in content:
  182.             value = 1.5
  183.             break
  184.         elif content == "soup bread":
  185.             value = 1.2
  186.             break
  187.         elif content == "soup salad":
  188.             value = 0.8
  189.             break
  190.         elif content == "bread soup":
  191.             value = 1.2
  192.             break
  193.         elif content == "bread salad":
  194.             value = 1.0
  195.             break
  196.         elif content == "salad soup":
  197.             value = 0.8
  198.             break
  199.         elif content == "salad bread":
  200.             value = 1.0
  201.             break
  202.         else:
  203.             print("Please input Soup, Bread or Salad")
  204.     calc = value * people
  205.     print("It will cost", calc, "to serve", content, "at your soup kitchen.")
  206.  
  207. def main():
  208.     print('''
  209.  
  210.    ██╗  ██╗   ███████╗   ██╗  ██╗
  211.    ██║  ██║   ██╔════╝   ██║  ██║
  212.    ███████║   █████╗     ███████║
  213.    ██╔══██║   ██╔══╝     ██╔══██║
  214.    ██║  ██║██╗██║     ██╗██║  ██║
  215.    ╚═╝  ╚═╝╚═╝╚═╝     ╚═╝╚═╝  ╚═╝
  216.  
  217. Habitat for Humanity management program.
  218. Copyright © 2014 KAB Studios. All Rights Reserved.                                                          ''')
  219.     #companyName = input("What is your company name?\n")
  220.     companyName = "Habitat for Humanity"
  221.     print()
  222.     print("Wecome to the %s money management" %companyName)
  223.     unixTime = time.time()
  224.     #print(unixTime)
  225.     realTime = datetime.fromtimestamp(unixTime).strftime('%Y-%m-%d')
  226.     #print(realTime)
  227.     money = 0.0
  228.     realCompanyName = companyName
  229.     hue0  = str(input("From what part of %s are you from?\n" %companyName))
  230.  
  231.     while True:
  232.         checkBank = input("Do you want to access the financial acount?\n").lower()
  233.         if checkBank == "yes":
  234.             bank(companyName,money,realCompanyName)
  235.             break
  236.         elif checkBank == "no":
  237.             break
  238.         else:
  239.             print("Please input Yes or No")
  240.     while True:
  241.         hue3 = input("Do you want to check the financial history?\n").lower()
  242.         if hue3 == "yes":
  243.             cool(companyName, realTime)
  244.         elif hue3 == "no":
  245.             break
  246.         else:
  247.             print("Please input Yes or No")
  248.  
  249.     while True:
  250.         hue4 = input("Do you want to calculate the price to build a new home?\n").lower()
  251.         if hue4 == "yes":
  252.             saving()
  253.             break
  254.         elif hue4 == "no":
  255.             break
  256.         else:
  257.             print("Please input Yes or No")
  258.     while True:
  259.         hue6 = input("Do you want to calculate how much money it would take to host a soup kitchen?\n").lower()
  260.         if hue6 == "yes":
  261.             soup()
  262.             break
  263.         elif hue6 == "no":
  264.             break
  265.         else:
  266.             print("Please input Yes or No")
  267.  
  268.     hue5 = input("Do you want to restart the program?\n").lower()
  269.  
  270.     if hue5 == "yes":
  271.         main()
  272.     else:
  273.         print("Thank you for using KAB programs! Goodbye!")
  274.        
  275.  
  276. try:
  277.     main()
  278. except ValueError as e:
  279.     print("Oops! That was not a valid number.")
  280. except Exception as e:
  281.     print(e)
  282. finally:
  283.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement