Changes

Jump to navigation Jump to search
6,245 bytes removed ,  12:50, 20 July 2010
Removed code, now in repo, updated links
Line 88: Line 88:     
==Links and Resources==
 
==Links and Resources==
Coming soon!
+
* [http://activities.sugarlabs.org/en-US/sugar/addon/4321/ Activity Page]
 
+
  * [http://gitorious.org/lemonade-stand-olpc/lemonade-stand-olpc Git Repository]
==Code so far==
+
* [https://fedorahosted.org/fossrit/wiki/LemonadeStand Project Trac]
<pre>
  −
#!/usr/env python
  −
# -*- coding: cp1252 -*-
  −
import random
  −
from counting import play_Money
  −
 
  −
 
  −
 
  −
#Generisize the names of supplys to make it easily editable
  −
#[0] = name of the stand, [1] = first supply, [2] = second supply, [3] = third supply, [4] = the object that is being sold
  −
variables = ['Lemonade Stand','cups','lemons','sugar','cups']
  −
 
  −
print 'Welcome to ' + variables[0]
  −
 
  −
#Random weather event, if its a hot day all stock will sell,
  −
# if its a normal day, 90% will sell, and if its a raining day 80% will sell
  −
 
  −
def weather_Change( ):
  −
    global weather
  −
    weather = random.randint( -1, 1 )
  −
   
  −
    if weather == -1:
  −
        print "It looks like its going to rain tomorrow"
  −
    elif weather == 0:
  −
        print "Its a normal day tomorrow"
  −
    elif weather == 1:
  −
        print "Tomorrow looks to be very hot"
  −
 
  −
#Format the input text, and make it return a 0 if input is incorrect
  −
def take_input(text, default = 0):
  −
    try:
  −
        in_text = input(text+" ["+`default`+"]: ")
  −
    except:
  −
        return default
  −
    if in_text < 0:
  −
        in_text = 0
  −
   
  −
    return in_text
  −
 
  −
#Declare a random event, More events can be added easily by building a new case statment
  −
def random_Event():
  −
    global stored_sugar, stored_lemons, stored_cups
  −
    event = random.randint(0, 10) 
  −
   
  −
    if event == 0:
  −
       
  −
        if stored_sugar > 10:
  −
            stored_sugar -= 10
  −
            print 'Ants steal your supplies!'
  −
        else:
  −
            stored_sugar = 0
  −
           
  −
    elif event == 1:
  −
 
  −
        print 'A lemon truck crashes in front of your stand!'
  −
        stored_lemons += 10
  −
       
  −
    elif event == 2:
  −
 
  −
        print 'It starts raining cups!'
  −
        stored_cups += 10
  −
 
  −
    print ""
  −
 
  −
 
  −
#Decreases currently the supply's by 10% each day
  −
def supply_Decay():
  −
    global stored_sugar, stored_lemons, stored_cups
  −
    if stored_sugar > 0:
  −
        stored_sugar -= 10 % stored_sugar
  −
    if stored_lemons > 0:
  −
        stored_lemons -= 10 % stored_lemons
  −
    if stored_cups > 0:
  −
        stored_cups -= 10% stored_cups
  −
 
  −
    return -1
  −
   
  −
# default values
  −
cup_price = .25
  −
lemon_price = 1.00
  −
sugar_price = .05
  −
weather = 0
  −
product_price = 1.50
  −
 
  −
#starting resources
  −
bank = 100
  −
 
  −
stored_cups = 0
  −
stored_lemons = 0
  −
stored_sugar = 0
  −
 
  −
# take in input
  −
num_days = take_input("How many days would you like to play for?", 30)
  −
 
  −
for day in range(1, num_days + 1):
  −
 
  −
   
  −
 
  −
 
  −
    print ""
  −
    print "____________________"
  −
    print "    Day number " + `day`
  −
    print "¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯"
  −
    print ""
  −
 
  −
    random_Event()
  −
 
  −
 
  −
    print "You have "+`stored_cups`+ " " + variables[1] + ", " +`stored_lemons`+ " " + variables[2] + ", and "+`stored_sugar`+ " " + variables[3] + " left."
  −
 
  −
    print variables[1] + " price: $" + `cup_price` + "    " + variables[2] + " price: $"+ "%.2f" % lemon_price + "    " + variables[3] + " price: $"+ "%.2f" % sugar_price
  −
 
  −
    expenses = 0
  −
 
  −
    cost_over = 1
  −
 
  −
 
  −
    #Checks to make sure you dont go over your bank amount while buying.
  −
 
  −
    while cost_over == 1:
  −
 
  −
        potential_expense = 0
  −
        in_num = take_input("How many " + variables[1])
  −
        potential_expense = expenses + (in_num * cup_price)
  −
 
  −
        if potential_expense < bank:
  −
            cost_over = -1
  −
            expenses += in_num * cup_price
  −
            stored_cups += in_num
  −
        else:
  −
            print 'You cant afford that many ' + variables[1]
  −
 
  −
    cost_over = 1
  −
 
  −
    while cost_over == 1:
  −
 
  −
        potential_expense = 0
  −
        in_num = take_input("How many " + variables[2])
  −
        potential_expense = expenses + (in_num * cup_price)
  −
 
  −
        if potential_expense < bank:
  −
            cost_over = -1
  −
            expenses += in_num * lemon_price
  −
            stored_lemons += in_num
  −
        else:
  −
            print 'You cant afford that many ' + variables[2]
  −
 
  −
    cost_over = 1
  −
 
  −
    while cost_over == 1:
  −
 
  −
      potential_expense = 0
  −
      in_num = take_input("How much " + variables[3])
  −
      potential_expense = expenses + (in_num * cup_price)
  −
 
  −
      if potential_expense < bank:
  −
          cost_over = -1
  −
          expenses += in_num * sugar_price
  −
          stored_sugar += in_num
  −
 
  −
      else:
  −
          print 'You can not afford that many ' + variables[3]
  −
 
  −
 
  −
 
  −
    # Find the lowest amount of supplys, and make that many of lemonade that day
  −
    sales = max(min(stored_cups, stored_lemons, stored_sugar),0)
  −
 
  −
    # Option 2: make as many as requested
  −
    stored_cups -= sales
  −
    stored_lemons -= sales
  −
    stored_sugar -= sales
  −
   
  −
    if weather == 0:
  −
        sales -= 10 % sales
  −
    elif weather == -1:
  −
        sales -= 20 % sales
  −
 
  −
 
  −
   
  −
    print `sales`+ ' ' + variables[4]+ " made for $"+ "%.2f" % expenses
  −
 
  −
    profit = sales * product_price
  −
    print `sales`+ " " + variables[4] +" were sold today for $"+ "%.2f" % profit
  −
   
  −
    print "You made $"+ "%.2f" % (profit - expenses)+" today."
  −
   
  −
   
  −
    if (profit - expenses) <= 0:
  −
   
  −
        print "You lost money today"
  −
       
  −
    else:   
  −
   
  −
        #If you didnt lose money that day, play the small money game to put away your change
  −
        #If you put away change right, you get to keep the profit, otherwise you lose it
  −
 
  −
        print "You go to put profits away"
  −
                 
  −
        if play_Money( int(profit - expenses) ) == 1:
  −
            print "you put the money away correctly"
  −
            bank += profit - expenses
  −
        else:
  −
            print "You lost the money when putting it away"
  −
   
  −
   
  −
    print "Current funds: $"+ "%.2f" % bank
  −
   
  −
    #Decrease the supply's by 10%
  −
    #Warn for the next days weather
  −
 
  −
    supply_Decay()
  −
    weather_Change()
  −
   
  −
   
  −
    print
  −
   
  −
print "Done!"
  −
 
  −
 
  −
</pre>
  −
 
  −
Counting code
  −
 
  −
<pre>
  −
 
  −
 
  −
dollar = 1
  −
quarter = .25
  −
dime = .10
  −
nickel = .05
  −
penny = .01
  −
 
  −
 
  −
 
  −
def take_input(text, default = 0):
  −
    try:
  −
        in_text = input(text+" ["+`default`+"]: ")
  −
    except:
  −
        return default
  −
    if in_text < 0:
  −
        in_text = 0
  −
   
  −
    return in_text
  −
 
  −
 
  −
def play_Money( money_Find ):
  −
  −
    global quarter, dime, nickel, penny
  −
   
  −
    total = 0
  −
   
  −
    #Takes the amount of money
  −
    total += dollar*take_input( "How many dollars? ")
  −
 
  −
   
  −
    total += quarter*take_input( "How many quarters? ")
  −
 
  −
    total += dime*take_input( "How many dimes? ")
  −
 
  −
    total += nickel*take_input( "How many nickels? ")
  −
 
  −
    total += penny*take_input( "How many pennies? ")
  −
           
  −
    if total == money_Find:
  −
        return 1
  −
           
  −
    else:
  −
        return -1
  −
       
  −
 
  −
</pre>
 
248

edits

Navigation menu