diff --git a/en/index.html b/en/index.html index 1368e8a..2298f69 100644 --- a/en/index.html +++ b/en/index.html @@ -44,12 +44,14 @@

Examples

  • Bouncing Ball
  • Number Guessing Game
  • +
  • Programmer's Paradise
  • Pig Latin Translator
  • 13 Coins
  • Trigonometry
  • Greenscreen
  • BMI
  • +
  • Magic Eye
  • Birthday Probability
  • Prime Factorization
  • @@ -70,6 +72,7 @@

    Examples

  • Lucky Draw
  • Leap year
  • +
  • Fisheye
  • E=MC2
  • Slot machine
  • diff --git a/en/paradise/index.html b/en/paradise/index.html new file mode 100644 index 0000000..3d2f2c1 --- /dev/null +++ b/en/paradise/index.html @@ -0,0 +1,257 @@ + +Programmer's Paradise + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    +
    +

    Programmer's Paradise

    +

    Written by Laryn Qi

    +
    +

    With the onset of COVID-19, online ordering has become even more prevalent. As software engineers, a program that could take our order from the comfort of our own terminal/command prompt would be especially convenient. Well, if we're truly programmers, why don't we try programming this program ourselves!

    +

    The main menu will consist of:

    +
      +
    • Boolean Burger: $4.99
    • +
    • Function Fries: $2.99
    • +
    • String Soda: $1.99
    • +
    +

    The secret menu will consist of:

    +
      +
    • Piech Perfection: $3.14
    • +
    • Sahami Special: a random price in the range $1.62-$2.72 (inclusive)
    • +
    +

    Write a program that prints out a short welcome message and the main menu. Then, it should continually read in menu items from the user, keeping track of how many items they've added so far. Misspelled items should result in an error message (this should not count as an additional item). During this ordering phase, the user can also ask to see the secret menu by typing in the key phrase "Secret Menu Please!" (this should not count as an additional item). If the user types nothing and just hits enter, the order phase should end. Lastly, it will print out the total price of the user's order and a farewell. Here is an example execution of the program:

    +
    Welcome to Programmer's Paradise!
    +----------
    +Here's our menu:
    +
    +Boolean Burger: $4.99
    +Function Fries: $2.99
    +String Soda: $1.99
    +
    +What can I get for you?
    +1. Boolean Burger
    +2. Function Fries
    +3. fries
    +Please enter a valid item.
    +3. Function Fries
    +4. String Soda
    +5. 
    +
    +Your total is...
    +$12.96
    +
    +Thank you for choosing Programmer's Paradise.
    +We hope you loop by again!
    +
    +
    +

    Here is another example execution of the program with secret menu items:

    +
    Welcome to Programmer's Paradise!
    +----------
    +Here's our menu:
    +
    +Boolean Burger: $4.99
    +Function Fries: $2.99
    +String Soda: $1.99
    +
    +What can I get for you?
    +1. String Soda
    +2. String Soda
    +3. Secret Menu Please!
    +----------
    +Here's our secret menu:
    +
    +Piech Perfection: $3.14
    +Sahami Special: $1.62-$2.72
    +
    +3. Piech Perfection
    +4. Sahami Special
    +5. 
    +
    +Your total is...
    +$8.92
    +
    +Thank you for choosing Programmer's Paradise.
    +We hope you loop by again!
    + 
    +

    Here are some tips for common issues:

    +
      +
    1. General +
        +
      • Your solution should take advantage of decomposition and constants
      • +
      +
    2. +
    3. Formatting +
        +
      • print() can be used to print out a blank line
      • +
      • The escape character \' can be used to display an apostrophe
      • +
      • Check out this StackOverflow thread if you're having trouble with trailing 0's
      • +
      +
    4. +
    5. Sahami Special +
        +
      • You will need to use the random library
      • +
      • Remember that all prices are floats (take a look at random.uniform and the Python built-in function round)
      • +
      +
    6. +
    +

    Optional Extensions

    +
      +
    1. Make ordering more realistic! Use the time library to delay printed outputs of your program so it feels like your terminal/command prompt is talking to you
    2. +
    3. Allow users to order multiple items at a time (1. 5 Boolean Burger)
    4. +
    5. Allow users to remove items from their order
    6. +
    7. Allow users to cancel their order entirely
    8. +
    9. Add your own items to the menu/secret menu!
    10. +
    +

     

    +

    Solution

    +

    + +

    +
    +
    import random
    +import time
    +
    +P_BURGER = 4.99 
    +P_FRIES = 2.99
    +P_SODA = 1.99
    +P_PIECH = 3.14
    +MIN_SAHAMI = 1.62
    +MAX_SAHAMI = 2.72
    +
    +def main():
    +    welcome()
    +    menu()
    +    order()
    +
    +def welcome():
    +    print('Welcome to Programmer\'s Paradise!')
    +    print('----------')
    +    time.sleep(1)
    +
    +def menu():
    +    print('Here\'s our menu:')
    +    print()
    +    time.sleep(1)
    +    print('Boolean Burger: $' + str(P_BURGER))
    +    time.sleep(1)
    +    print('Function Fries: $' + str(P_FRIES))
    +    time.sleep(1)
    +    print('String Soda: $' + str(P_SODA))
    +    time.sleep(1)
    +    print()
    +    
    +
    +def secret_menu():
    +    print('----------')
    +    print('Here\'s our secret menu:')
    +    time.sleep(1)
    +    print()
    +    print('Piech Perfection: $' + str(P_PIECH))
    +    time.sleep(1)
    +    print('Sahami Special: $' + str(MIN_SAHAMI) + '-$' + str(MAX_SAHAMI))
    +    time.sleep(1)
    +    print()
    +
    +def order():
    +    print('What can I get for you?')
    +    count = 1
    +    total = 0
    +    item = input('1. ')
    +    while item != '':
    +        if item == 'Boolean Burger':
    +            total += P_BURGER
    +        elif item == 'Function Fries':
    +            total += P_FRIES
    +        elif item == 'String Soda':
    +            total += P_SODA
    +        elif item == 'Secret Menu Please!':
    +            secret_menu()
    +            count -= 1
    +        elif item == 'Piech Perfection':
    +            total += P_PIECH
    +        elif item == 'Sahami Special':
    +            total += random.uniform(MIN_SAHAMI, MAX_SAHAMI)
    +        else:
    +            print('Please enter a valid item.')
    +            count -= 1
    +        count += 1
    +        item = input(str(count) + '. ')
    +    
    +    print()
    +    print('Your total is...')
    +    time.sleep(1)
    +    print('$' + "%.2f" % round(total, 2))
    +    time.sleep(1)
    +    print()
    +    print('Thank you for choosing Programmer\'s Paradise.')
    +    time.sleep(1)
    +    print('We hope you loop by again!')
    +    time.sleep(1)
    +    print()
    +    exit()
    +
    +if __name__ == '__main__':
    +    main()
    +
    + + + + +
    +
    +
    +
    + + diff --git a/en/slot-machine/index.html b/en/slot-machine/index.html index ef9a73e..5e3cab1 100644 --- a/en/slot-machine/index.html +++ b/en/slot-machine/index.html @@ -165,10 +165,10 @@

    Solution

    print(three, flush=True) time.sleep(SPIN_PAUSE_INTERVAL) - if one == two or two == three or one == three: - return WINNINGS_FOR_TWO - elif one == two and two == three: + if one == two and two == three: return WINNINGS_FOR_THREE + elif one == two or two == three or one == three: + return WINNINGS_FOR_TWO else: return -SPIN_COST diff --git a/examples/paradise/credit.txt b/examples/paradise/credit.txt new file mode 100644 index 0000000..401ff12 --- /dev/null +++ b/examples/paradise/credit.txt @@ -0,0 +1 @@ +Written by Laryn Qi \ No newline at end of file diff --git a/examples/paradise/index.html b/examples/paradise/index.html new file mode 100644 index 0000000..4cabd59 --- /dev/null +++ b/examples/paradise/index.html @@ -0,0 +1,96 @@ +

    With the onset of COVID-19, online ordering has become even more prevalent. As software engineers, a program that could take our order from the comfort of our own terminal/command prompt would be especially convenient. Well, if we're truly programmers, why don't we try programming this program ourselves!

    +

    The main menu will consist of:

    + +

    The secret menu will consist of:

    + +

    Write a program that prints out a short welcome message and the main menu. Then, it should continually read in menu items from the user, keeping track of how many items they've added so far. Misspelled items should result in an error message (this should not count as an additional item). During this ordering phase, the user can also ask to see the secret menu by typing in the key phrase "Secret Menu Please!" (this should not count as an additional item). If the user types nothing and just hits enter, the order phase should end. Lastly, it will print out the total price of the user's order and a farewell. Here is an example execution of the program:

    +
    Welcome to Programmer's Paradise!
    +----------
    +Here's our menu:
    +
    +Boolean Burger: $4.99
    +Function Fries: $2.99
    +String Soda: $1.99
    +
    +What can I get for you?
    +1. Boolean Burger
    +2. Function Fries
    +3. fries
    +Please enter a valid item.
    +3. Function Fries
    +4. String Soda
    +5. 
    +
    +Your total is...
    +$12.96
    +
    +Thank you for choosing Programmer's Paradise.
    +We hope you loop by again!
    +
    +
    +

    Here is another example execution of the program with secret menu items:

    +
    Welcome to Programmer's Paradise!
    +----------
    +Here's our menu:
    +
    +Boolean Burger: $4.99
    +Function Fries: $2.99
    +String Soda: $1.99
    +
    +What can I get for you?
    +1. String Soda
    +2. String Soda
    +3. Secret Menu Please!
    +----------
    +Here's our secret menu:
    +
    +Piech Perfection: $3.14
    +Sahami Special: $1.62-$2.72
    +
    +3. Piech Perfection
    +4. Sahami Special
    +5. 
    +
    +Your total is...
    +$8.92
    +
    +Thank you for choosing Programmer's Paradise.
    +We hope you loop by again!
    + 
    +

    Here are some tips for common issues:

    +
      +
    1. General + +
    2. +
    3. Formatting + +
    4. +
    5. Sahami Special + +
    6. +
    +

    Optional Extensions

    +
      +
    1. Make ordering more realistic! Use the time library to delay printed outputs of your program so it feels like your terminal/command prompt is talking to you
    2. +
    3. Allow users to order multiple items at a time (1. 5 Boolean Burger)
    4. +
    5. Allow users to remove items from their order
    6. +
    7. Allow users to cancel their order entirely
    8. +
    9. Add your own items to the menu/secret menu!
    10. +
    +

     

    \ No newline at end of file diff --git a/examples/paradise/soln.py b/examples/paradise/soln.py new file mode 100644 index 0000000..c8dc068 --- /dev/null +++ b/examples/paradise/soln.py @@ -0,0 +1,84 @@ +import random +import time + +P_BURGER = 4.99 +P_FRIES = 2.99 +P_SODA = 1.99 +P_PIECH = 3.14 +MIN_SAHAMI = 1.62 +MAX_SAHAMI = 2.72 + +def main(): + welcome() + menu() + order() + +def welcome(): + print('Welcome to Programmer\'s Paradise!') + print('----------') + time.sleep(1) + +def menu(): + print('Here\'s our menu:') + print() + time.sleep(1) + print('Boolean Burger: $' + str(P_BURGER)) + time.sleep(1) + print('Function Fries: $' + str(P_FRIES)) + time.sleep(1) + print('String Soda: $' + str(P_SODA)) + time.sleep(1) + print() + + +def secret_menu(): + print('----------') + print('Here\'s our secret menu:') + time.sleep(1) + print() + print('Piech Perfection: $' + str(P_PIECH)) + time.sleep(1) + print('Sahami Special: $' + str(MIN_SAHAMI) + '-$' + str(MAX_SAHAMI)) + time.sleep(1) + print() + +def order(): + print('What can I get for you?') + count = 1 + total = 0 + item = input('1. ') + while item != '': + if item == 'Boolean Burger': + total += P_BURGER + elif item == 'Function Fries': + total += P_FRIES + elif item == 'String Soda': + total += P_SODA + elif item == 'Secret Menu Please!': + secret_menu() + count -= 1 + elif item == 'Piech Perfection': + total += P_PIECH + elif item == 'Sahami Special': + total += random.uniform(MIN_SAHAMI, MAX_SAHAMI) + else: + print('Please enter a valid item.') + count -= 1 + count += 1 + item = input(str(count) + '. ') + + print() + print('Your total is...') + time.sleep(1) + print('$' + "%.2f" % round(total, 2)) + time.sleep(1) + print() + print('Thank you for choosing Programmer\'s Paradise.') + time.sleep(1) + print('We hope you loop by again!') + time.sleep(1) + print() + exit() + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/examples/paradise/tags.txt b/examples/paradise/tags.txt new file mode 100644 index 0000000..a88aa0c --- /dev/null +++ b/examples/paradise/tags.txt @@ -0,0 +1,9 @@ +week2 +Python +functions +decomposition +constants +input +random +user +fun \ No newline at end of file diff --git a/examples/paradise/title.txt b/examples/paradise/title.txt new file mode 100644 index 0000000..43dfc46 --- /dev/null +++ b/examples/paradise/title.txt @@ -0,0 +1 @@ +Programmer's Paradise \ No newline at end of file diff --git a/plugins/__pycache__/__init__.cpython-37.pyc b/plugins/__pycache__/__init__.cpython-37.pyc index 578955e..33a6691 100644 Binary files a/plugins/__pycache__/__init__.cpython-37.pyc and b/plugins/__pycache__/__init__.cpython-37.pyc differ diff --git a/plugins/bottle/__pycache__/__init__.cpython-37.pyc b/plugins/bottle/__pycache__/__init__.cpython-37.pyc index f91f539..325cdc2 100644 Binary files a/plugins/bottle/__pycache__/__init__.cpython-37.pyc and b/plugins/bottle/__pycache__/__init__.cpython-37.pyc differ diff --git a/plugins/bottle/__pycache__/bottle.cpython-37.pyc b/plugins/bottle/__pycache__/bottle.cpython-37.pyc index 59e2f3a..a0c718d 100644 Binary files a/plugins/bottle/__pycache__/bottle.cpython-37.pyc and b/plugins/bottle/__pycache__/bottle.cpython-37.pyc differ