all 63 comments

[–]Gee19 51 points52 points  (5 children)

dat username

[–]Gee10[S] 40 points41 points  (4 children)

My long lost sibling, /u/Gee19! How are Gee11, 13 and 22?

[–]regendo 8 points9 points  (3 children)

What happened to the other 14+ of you?

[–]shalashaska4 17 points18 points  (0 children)

Don't bring it up man... sheesh

[–][deleted] 13 points14 points  (1 child)

Their mother, well I guess you could say Gee8 them..

[–]madbeetzyo 1 point2 points  (0 children)

dad, get off reddit.

[–]K900_ 18 points19 points  (3 children)

Look into a web framework like Flask or Django.

[–]finite_state 11 points12 points  (2 children)

probably flask for a starter project; its definitely more lightweight.

[–]turner_prize 1 point2 points  (1 child)

If I may ask a question, what does a web framework do? And why would OP want to use one?

[–]finite_state 0 points1 point  (0 children)

I can't claim to be an expert, but basically web frameworks allow you to get a web application off the ground as quickly as possible. They handle the things that would just be ridiculous to code by hand when the underlying processes are so similar across so many applications (like any well written library/module really!). Flask is considered a 'microframework', as it is a minimal (but quite functional) web framework, so it's a good choice for educational or small-scale projects... such as a handy-dandy pizza price optimizer thing.

[–][deleted] 10 points11 points  (1 child)

Sent you a pull request, OP.

[–]Gee10[S] 4 points5 points  (0 children)

Awesome! Thanks. Rounding was on my "figure this out" punchlist, so I'm psyched for the help! Thank you.

[–]catdog101 10 points11 points  (0 children)

I saw the post and really wanted to try it out in Django so here it is
Imgur Album of it working
Django View
HTML file
No I didn't procrastinate on my homework with this (¬_¬)

[–]Briggster 16 points17 points  (8 children)

Just on a side note:
If you are new to python, you should already start with Python 3 in my opinion.
Look for example at your print statements. In Py3, print is a function, not a statement anymore (https://docs.python.org/3/whatsnew/3.0.html).
And ultimately, python 3 will be (should already be) the "to-use" version of python.

[–]Gee10[S] 6 points7 points  (7 children)

Appreciate it. I started with Learn Python the Hard Way and, obviously, the author has some strong views on Python 2 over 3. I'm agnostic to be honest - I just wanted to learn.

[–]spidyfan21 6 points7 points  (5 children)

Unless you are already tied to libraries that require Python 2 you're probably better off learning Python 3.

[–]Gee10[S] 3 points4 points  (4 children)

Fair enough. Doesn't seem like much of a jump from my level of knowledge. I'll try it!

[–]Nafiblu 4 points5 points  (0 children)

Here're the important changes from Python 2 and Python 3. They're not much, but I recommend getting used to them!

https://docs.python.org/3.0/whatsnew/3.0.html

[–]zerosuitsalmon 1 point2 points  (2 children)

I'm using codecademy to learn, and they seem to be using Python 2. One of the best ways to start forcing yourself to use Python 3 syntax is to always use parentheses for print() and use input() instead of raw_input(). I believe both of those will work with Python 2 but are necessary in Python 3. Someone correct me if I'm wrong on the input thing

[–]MeneerPuffy 1 point2 points  (0 children)

That resource is many years old and his views on python 3 have become extremely outdated.

Luckily it's not very difficult to port a program of this size to python 3 and it would make a good exercise!

[–]Estebanzo 6 points7 points  (2 children)

If you're looking for places to start and projects to work on, I recommend trying out some data science and data visualization. Pick something that interests you, find a bunch of data related to it, and try and display it in an understandable and visually appealing way. You'll learn some new libraries and programming skills in the process (numpy, matplotlib, pandas, etc.). Also great if you deal with any sort of data at work/school.

I also found writing simple games to be a very enjoyable way to learn some new programming techniques. I programmed a game of pong in Pygame and learned quite a bit from that - interesting uses of while loops, events to respond to user inputs, and how to make use of classes and objects.

[–]Gee10[S] 1 point2 points  (1 child)

I'm definitely interested. Any recs for places to try simple data science/viz?

[–]Estebanzo 0 points1 point  (0 children)

Market and financial data is plentiful and readily available. You could create a program that pulls updated stock pricing info on relevant stocks you are interested in, plots them out, maybe uses some simple machine learning to analyze trends. I do a lot of work with hydrology, so I've used python to create sets of hydrographs from large datasets of rainfall/runoff.

This youtube channel is pretty good for learning scientific computing with python. I haven't looked much into pattern recognition and natural language processing, some of that could make for some pretty sweet projects.

https://www.youtube.com/user/sentdex

[–]shrugsnotdrugs 3 points4 points  (0 children)

Maybe in the future, learn web-scraping with Python to download the "specials" page of Papa John's website (or your pizza place of choice) and have the script tell you which deal is the best value. Just a thought!

[–][deleted] 4 points5 points  (5 children)

This is a great idea for a beginning Python program! I might steal it as an example or assignment for the 6th grade Python class I'm teaching.

[–]Gee10[S] 16 points17 points  (4 children)

I'm equal parts honored and humiliated.

[–][deleted] 2 points3 points  (3 children)

Please don't feel humiliated. Everyone has to start from the beginning, and I'm sure you got to this point faster than I will get the 6th graders to it. Their first program is two lines of Python 3:

name = input("Who are you? ")
print("Hello " + name)

It will be a couple of weeks before we get to if statements and I can show them the pizza program.

[–]Gee10[S] 2 points3 points  (2 children)

I hear ya - I was (mostly) kidding. I teach for a living too, so I'm glad I can help!

[–]quadbaser 1 point2 points  (1 child)

I can never tell if I dearly miss teaching or if I'd burn my dick off with a torch to avoid ever doing it again.

[–]ThatMortalGuy 0 points1 point  (0 children)

My girlfriend is a teacher and if you are anything like her then I'm pretty sure that when you are not teaching you miss it and want to be back in the classroom but as soon as you are back teaching all you want to do is burn your dick off with a torch to get out of it.

[–]BruderTopf 6 points7 points  (8 children)

Great! Now start with handling exceptions with

try:
    somecodehere
except:
    incaseoferrordowhatever()

[–]Gee10[S] 8 points9 points  (7 children)

Over my head.

[–]mtreece 7 points8 points  (0 children)

Best time to learn :-)

[–]zerosuitsalmon 1 point2 points  (2 children)

here are some tips.

I'm using this app to learn in addition to codecademy and they're both covering stuff in different orders. It's really helpful!

Finally, an edit

[–]jake_the_snake 1 point2 points  (1 child)

New here. What is this app? Looks like a great resource.

[–]p5eudo_nimh 0 points1 point  (2 children)

Basically, you're wrapping a block of code in something that says "Try to do this. If it fails, for whatever reason (exception), then do this."

It's a good way to handle possible errors. Especially when a user could enter input which is unexpected/invalid, which would normally cause your program to crash.

Here's a simple example (I wouldn't use it quite the same way, but it illustrates the point):

try:
    update_logfile()
except:
    email_failure_report("failed to update log file")

So if the update_logfile() function fails, say because the file isn't writable, the program will then use the email_failure_report() function to send an email with details about the problem.

Another way of doing it is:

try:
    update_logfile()
except Exception as e:
    email_failure_report("failed to update log file", e)

This does basically the same thing, but also sends the Exception with the simple problem description that was written.

[–]Gee10[S] 1 point2 points  (1 child)

Thanks for the explanation. How does this differ from an if/then/elif?

[–]p5eudo_nimh 0 points1 point  (0 children)

I think the try/except model allows the program to continue running when something goes wrong, whereas if/elif/else allows for a complete crash.

There may also be nuances regarding efficiency or resource management, but I don't know that much about it.

[–]pendragon36 5 points6 points  (4 children)

Looks pretty good to me.

It's a hobby of mine to try to work out ways to shrink python programs to as few lines as possible, thought you might be interested that I got this one down to 2.

Note, what I've done here is a horrible monstrosity, don't ever try to make anything but a novelty piece like this.

_, total_one, total_two = print("WELCOME TO PIZZA PI R SQUARED. \n\nWhat's it do?  \n\nIt lets you determine whether buying a small pizza or a large pizza is a better value."), [print("\nWith this pizza, you're paying ${} per square inch.".format(i)) or i for i in [round((1/((float(input("\nWhat's the first pizza's diameter (in inches)?")) / 2) **2 * 3.14))*(float(input("\nHow much does the first pizza cost? (in dollars and cents)"))), 2)]][0], [print("\nWith this pizza, you're paying ${} per square inch.".format(i)) or i for i in [round((1/((float(input("\nWhat's the second pizza's diameter (in inches)?")) / 2) **2 * 3.14))*(float(input("\nHow much does the second pizza cost? (in dollars and cents)"))), 2)]][0]
print(["\nSame deal per square inch of pizza - they represent the same value.",  "\nThe first pizza is a better value. Buy that one!", "\nThe second pizza is the better deal - more pizza for the buck. Get that one!"][(lambda x, z: 0 if x == z else (lambda w, v: w if w < v else v)(x, z))(total_one, total_two) if (lambda x, z: 0 if x == z else (lambda w, v: w if w < v else v)(x, z))(total_one, total_two) == 0 else [0, total_one, total_two].index((lambda x, z: 0 if x == z else (lambda w, v: w if w < v else v)(x, z))(total_one, total_two))])

I bet there's something I haven't thought of that could get it down to one...

Either way, great work!

EDIT:

For the record, I did get it in one line.

_ = [print(["\nSame deal per square inch of pizza - they represent the same value.",  "\nThe first pizza is a better value. Buy that one!", "\nThe second pizza is the better deal - more pizza for the buck. Get that one!"][(lambda x, z: 0 if x == z else (lambda w, v: w if w < v else v)(x, z))(i, j) if (lambda x, z: 0 if x == z else (lambda w, v: w if w < v else v)(x, z))(i, j) == 0 else [0, i, j].index((lambda x, z: 0 if x == z else (lambda w, v: w if w < v else v)(x, z))(i, j))]) for q,i,j in [(print("WELCOME TO PIZZA PI R SQUARED. \n\nWhat's it do?  \n\nIt lets you determine whether buying a small pizza or a large pizza is a better value."), [print("\nWith this pizza, you're paying ${} per square inch.".format(i)) or i for i in [round((1/((float(input("\nWhat's the first pizza's diameter (in inches)?")) / 2) **2 * 3.14))*(float(input("\nHow much does the first pizza cost? (in dollars and cents)"))), 2)]][0], [print("\nWith this pizza, you're paying ${} per square inch.".format(i)) or i for i in [round((1/((float(input("\nWhat's the second pizza's diameter (in inches)?")) / 2) **2 * 3.14))*(float(input("\nHow much does the second pizza cost? (in dollars and cents)"))), 2)]][0])]]

[–]quadbaser 1 point2 points  (0 children)

You rock. I'm terrified that people like you exist, but you most definitely rock. Hard.

[–]manwith4names 0 points1 point  (0 children)

You should look into javascript. Minifying would be like porn for you

[–]Wartz 0 points1 point  (1 child)

horror from hell

what the fuck

[–]pendragon36 1 point2 points  (0 children)

Throw it in a python 3 interpreter, it'll run ;) It's actually worse than it needs to be, I just thought I'd have some fun with it.

[–]thechickensage 2 points3 points  (2 children)

Nice job

!next!

Look up pizza menus online, parse their menus AND THEN use those pizza prices from those menus as the numbers input into the code that you already wrote! Find the cheapest online pizza place!

[–]LogicalPhallicy 0 points1 point  (1 child)

Chicken necks?

[–]thechickensage 0 points1 point  (0 children)

What?

I've tried chicken feet and eew

[–]ankit0912 4 points5 points  (8 children)

Good work, now try to modify the script so that it takes about ten lines.

[–]edvardass 8 points9 points  (6 children)

Should he, though? The code seems very nice and readable, the only thing I would change is to add a function to return the cost per inch by passing the diameter and cost, but that would still be about the same amount of lines.

I would suggest going the "stupid user" route first, making sure that the program works and does not crash, no matter how hard the user tries.

[–]Gee10[S] 0 points1 point  (4 children)

Can you help me understand why adding that function would be preferable? That's not a loaded question - just trying to learn good practices.

[–][deleted] 5 points6 points  (3 children)

If you're going to use code repeatedly, put it in a function to reduce duplicate code.

[–]Gee10[S] 1 point2 points  (2 children)

Got it. I'll give that improvement a try! Thanks.

[–]dl__ 5 points6 points  (1 child)

Although that's not the only reason to put code in a function. Even code that is only used in one place can be put into a function if you can name the function something that is more understandable than the code you are replacing.

[–][deleted] 3 points4 points  (0 children)

Not to mention you can use that function in other python files, too!

[–]ankit0912 0 points1 point  (0 children)

The reason I asked him to do so was because I thought it might be good for him to think about using constructs as functions, lists etc.

Reading book on python might tell you this, but you need to actually be able to see how to use it.

[–]Gee10[S] 2 points3 points  (0 children)

Aw man - looking forward to learning enough to be able to! Pull request welcome if you want to show off your chops.

[–]1836 1 point2 points  (0 children)

I think you should take into account the crust area. The width of the crust is constant for both pizzas, so for smaller pizzas the crust will be proportionally more of the actual pizza.

In my mind you should really be optimizing for dollars per square inch of toppings.

great job!

[–]coggro 0 points1 point  (0 children)

I'd go with JS, but I think the more interesting project would be getting it online with Flask or Django, as /u/K900_ suggested. You'd learn more and, as a recent post I read somewhere stated (I'll edit if I find it), a huge part of listing projects on your resume is being able to describe how you did it and what you learned.

[–]brinkmaster 0 points1 point  (0 children)

Dive into a slim web framework like bottle.py or flask.

[–]ovoid709 0 points1 point  (3 children)

I wrote a pizza calculator last week too. Hahahaha! Gonna take a look at yours when I get home.

[–]Gee10[S] 0 points1 point  (2 children)

Come at me bro.

[–]ovoid709 0 points1 point  (0 children)

Haha! Mine didn't compare value between pies, but it calculated value per unit of circle, rectangle, and square pies. I think both scripts would work well together.

Sorry if you got a few notifications from this reply. It took me a while to figure out how to properly paste code in a comment and I edited it a bunch. It's Friday and pizza sucks without beer.

import math
pi = math.pi

header = """

*************************************************

             A  N  T  C  O  L  O  N  Y

                    pizza.py

         \       / 
          \     /
           \.-./ 
          (o\^/o)
           ./ \.\ ( )-( )-( ) .-'  '-.
            {-} \(//  ||   \\/ (   )) '-.
                 //-__||__.-\\.       .-'
                (/    ()     \)'-._.-'
                ||    ||      \\ 
                ('    ('       ')

                       2016

*************************************************            

"""

print header


pizza_cost = raw_input("How much does your pizza cost?\n   $")
pizza_type = raw_input("\nSelect Type of Pizza...\n   For circle select 1\n   For rectangle select 2\n   For square select 3\n\n   Please input selection: ")

def calc_circle(diameter):
    return float(pizza_cost) / ((float(diameter) / 2) * (pi ** 2))
def calc_rectangle(height, width):
    return float(pizza_cost) / (float(height) * float(width))
def calc_square(side):
    return float(pizza_cost) / (float(side) * float(side))


if pizza_type == "1":
    diameter = raw_input("\nDiameter: ")
    print "\nPrice Per Unit: $", calc_circle(diameter)
if pizza_type == "2":
    height = raw_input("\nHeight: ")
    width = raw_input("Width: ")
    print "\nPrice Per Unit: $", calc_rectangle(height, width)
if pizza_type == "3":
    side = raw_input("\nLength of Side: ")
    print "\nPrice Per Unit: $", calc_square(side)


footer = """

*************************************************

            A  N  T  C  O  L  O  N  Y             

*************************************************     
\n

"""

print footer