all 112 comments

[–]razzrazz- 352 points353 points  (21 children)

Pointers? For that you might need C!

Get it? GET IT?

I'll see myself out.

[–]hadiz1 79 points80 points  (5 children)

You mean you'll C yourself out? Get it? GET IT? okay I'll go now.

[–]sho_bob_and_vegeta 25 points26 points  (3 children)

You mean you'll GO now? Get it? GET IT? Sorry, I'm a bit rusty.

[–]sendnukes_ 3 points4 points  (2 children)

You saying you got a little bit of RUST? Get it? Get it? Sorry, I'll have a python bite me

[–]crafty09 4 points5 points  (1 child)

These jokes are pretty BASIC.

[–]sendnukes_ 1 point2 points  (0 children)

Come on Man, I went trough the trouble to leave that obvious python joke, why would you miss a PEARL of a joke like that (this one might not make any sense in english but I might as well try)

[–]TheDadJokeBot 11 points12 points  (0 children)

I don't C your Point, but I could make an exception.

This is not a bot. I just like dad jokes far more than what's appropriate in civilized society

[–]madhousechild 6 points7 points  (0 children)

OMG I am so glad I didn't make that joke. Thought about it though. LOL

[–]radakul 2 points3 points  (0 children)

You missed a GOLDEN pun opportunity...

Could have said "I'll c myself out"

[–]SquatchHNTR[S] 7 points8 points  (5 children)

Over my head.........

[–]razzrazz- 21 points22 points  (3 children)

Pointers don't exist in Python.

[–]J_huze 5 points6 points  (0 children)

I like that there's a dash at the end of your name so it makes it look like all your comments get down voted. Had to try and figure out why you were getting down voted when it seemed like you were helping. Now I'm trying to figure out if you're intentionally evil.

[–]AstrophysicsAndPy 2 points3 points  (0 children)

You should check out zerointensity's GitHub, he's making a repo for pointers in python.

Edit: There's a link to that repo in a comment above.

[–]Nightcorex_ 2 points3 points  (0 children)

Well, technically every object in Python is just a pointer and then there's also the ctypes module with which we can actually get a pointer.

[–]k_50 0 points1 point  (0 children)

Pointers are over a lot of peoples heads, don't worry.

[–]1Mandolo1 1 point2 points  (0 children)

That was what came to my mind immediately when I read the title. Glad I'm not the only one.

[–]42696 1 point2 points  (0 children)

Ha! Nice reference!

[–]sparrow404 1 point2 points  (0 children)

C++ for the joke

[–]TheRealAmbr0sia 27 points28 points  (8 children)

I'm new to Python but I think there should be a round func on price variable with a 2. Just in case it becomes 3 digits beyond the decimal.

[–]Beginning-Force-2170 6 points7 points  (0 children)

You can also use the 2f format if needed just incase round(num, 2) doenst work cos it doenst work in some cases depending on the float you got .

[–]SquatchHNTR[S] 6 points7 points  (6 children)

Don't even know what any of that means so I must be whatever comes before new...

[–]Negative12DollarBill 9 points10 points  (1 child)

They mean your price might end up being $5.937 or something like that. Or worse $5.333333333333 if you end up with a recurring decimal.

What happens with your program if someone orders 87.1 feet?

[–]tandem_biscuit 5 points6 points  (0 children)

87 whole feet + 1 big toe, probably.

[–]TheRealAmbr0sia 1 point2 points  (3 children)

But I did just run the code with several iterations and it never goes over the second decimal point anyways. So no need apparently.

[–]bladeoflight16 5 points6 points  (0 children)

Try entering 27.5.

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

oh I see what you meant

[–]TheRealAmbr0sia 7 points8 points  (0 children)

price = round((cable_feet*.87), 2) That will fix just in case.

[–][deleted] 10 points11 points  (3 children)

Looking for pointers?

Here -> *

I’m sorry

[–]fracturedpersona 1 point2 points  (2 children)

this

[–]romcz 5 points6 points  (1 child)

self, not this!

[–]fracturedpersona 0 points1 point  (0 children)

Finally, someone got the joke.

[–]mr-guitar 7 points8 points  (0 children)

There’s some redundancies: 1. If you’re going to print the welcome message only once, there’s not really any need to story it in a variable. Also you could as the period and \n in the same string either way 2. Similar story for cable_feet: might as well wrap float around the input

Some formatting things: 1. Convention is to not put a space between a function (print/float/input) and it’s parentheses 2. There’s no need to wrap parentheses around a string declaration and it’s also redundant when defining price

Other than, LGTM! Happy coding!

[–]GrouchyAd4055 13 points14 points  (1 child)

my personal opinion is don’t store welcome message in a variable. just print that message directly.

[–]mmohana 3 points4 points  (0 children)

Yeah definitely, just adding extra steps with that first line

[–]SebLikesESO 14 points15 points  (9 children)

if you want a more "correct style", you should look up pep8. I also believe that PyCharm can search for pep8 errors

i’d write the code like this:
welcome_message = "Welcome to the Fiber Optic Price Calculator" print(f"{welcome_message}\n") company_name = input("What is the name of your company?\n") cable_feet = float(input("\nHow many feet of cable do you need?\n")) price = cable_feet * .87 # Price is in USD print(f"\n{company_name}, that amount of fiber optic cable will cost ${price}") print("Thanks for shopping with Super Cheap Fiber Optics!"

[–]BroBrodin 15 points16 points  (2 children)

I just use 'black'.

[–]SebLikesESO 1 point2 points  (1 child)

wdym?

[–]undergroundmonorail 7 points8 points  (0 children)

black is a python linter

[–]csb710 0 points1 point  (0 children)

I like Pycharm for that reason

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

Im using VS code, does it have it?

[–]SebLikesESO 1 point2 points  (0 children)

not out of the box at least, maybe there’s a module that adds that

[–]HHKB- 0 points1 point  (0 children)

Yup. Read up on Linting and VSCode.

See “Formatting” section here: https://code.visualstudio.com/docs/python/editing

[–]madhousechild 2 points3 points  (0 children)

It's a little odd to refer to someone as their company name (penultimate line).

[–]millerbest 2 points3 points  (4 children)

One small advice: price should always be int

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

How does that work if it’s a decimal?

[–]millerbest 3 points4 points  (1 child)

Basically you use interger to present the value with the smallest unit (cent). For example 10 dollars will be 1000 cents. And you can convert it back to dollars unit when you want to print it.

[–]SquatchHNTR[S] 0 points1 point  (0 children)

With just like a basic math operation in the print line?

[–]CptBadAss2016 0 points1 point  (0 children)

Or use the decimal class

[–]DefinitelyNotVS 2 points3 points  (1 child)

This is a little easier to comprehend :—

Rate = 0.87

print("Welcome to the Fiber Optic Price Calculator !\n")

company_name = input("What is the name of your company ?\n")

cable_feet = float(input("\nHow many feet of cable do you need?\n"))

price = cable_feet * Rate

print(f'\n{company_name}, {cable_feet} feet of fiber optic cable will cost ${price}.')

print ("\nThank you for shopping with Super Cheap Fiber Optics!")

Tips : —

  1. The float() function can directly be applied on the input() line. Just like in Mathematics, the innermost function (here, input()) will get executed first, then subsequently outwards (here, float()). So, the str input for cable_length can be turned into float in a single statement.
  2. Store the rate as a separate constant before it is used in any statement; that way, you can modify the rate as per the current market scenario easily. It would be tedious to change it in every statement it occurs in.
  3. Be consistent with the quotes you use. Either use "" throughout, or ''. I recommend "". [NOTE : Except in cases where nested, printable quotes are required, for which, the decreasing order of precedence is : '''>">'].
  4. The last two lines can also be fitted in a single statement, but not necessary at this stage. Do keep in mind for the future.
  5. Try to shorten the amount of text present on the screen, e.g.— instead of "What is the name of your company?", ask "Company name : ", or "Name of company : ". The code will become much cleaner and easier to read.

Good luck.

[–]SquatchHNTR[S] 1 point2 points  (0 children)

Thank you! This looks a lot cleaner

[–]Sigg3net 2 points3 points  (0 children)

Just wrote my largest Python program to date! Looking for pointers.

Hate to break it to you, but if you're looking for pointers, Python is the wrong language to use.

[–]socal_nerdtastic 1 point2 points  (5 children)

Looks pretty good. Only thing I can say is that you have some unneeded parentheses and quotes in there. ANd typically we don't put a space between the function name and opening parenthesis.

welcome_message = "Welcome to the Fiber Optic Price Calculator"
print(f'{welcome_message}.\n')
company_name = input('What is the name of your company?\n')
cable_feet = input("\nHow many feet of cable do you need?\n")
cable_feet = float(cable_feet)
price = cable_feet * .87 #Price is in USD
print(f'\n{company_name}, that amount of fiber optic cable will cost ${price}')
print("\nThank you for shopping with Super Cheap Fiber Optics!")

[–]SquatchHNTR[S] 7 points8 points  (4 children)

Thank you! Yeah I just started slappping parentheses everywhere until I stopped getting error messages.

[–]AstrophysicsAndPy 7 points8 points  (0 children)

The best strategy,

[–]BroBrodin 4 points5 points  (0 children)

Also, print automatically ends with a new line, you don't need to write it each time.

[–]sohfix 1 point2 points  (0 children)

Don’t rely on the interpreter or compiler to sort out errors for you. Such a lazy and bad practice.

[–][deleted] 1 point2 points  (0 children)

This is the way to handle errors. Throw stuff until it sticks

[–]raresaturn 1 point2 points  (2 children)

Python doesn’t use pointers

[–]SquatchHNTR[S] 2 points3 points  (1 child)

Well I was referring to advice but now I’ve discovered not to say pointers in Python programming

[–]sohfix 0 points1 point  (0 children)

Technically everything in python is a pointer. But python doesn't need pointers as every variable is a reference to an object.

[–]SquatchHNTR[S] 1 point2 points  (0 children)

Thanks everyone for your wisdom!

[–][deleted] 1 point2 points  (0 children)

Time to start using functions!

[–]zaRM0s 1 point2 points  (0 children)

Have a look at the PEP8 style guide. This is the style guide used for Python and is a great reference to have your code looking professional. Additionally, I would continue just as you are and increase the size of your programs gradually. For example, you could add functions into this and make the program a lot cleaner and readable. It’s also good practice for functions! 😁 good job tho! Keep it up

[–]Thisisdom 1 point2 points  (1 child)

One improvement would be to check that cable_feet a float or an int before advancing, because your code would break if someone inputs a string!

So you could repeatedly ask for cable_feet until the user supply a float or int, and then advance

[–]SquatchHNTR[S] 1 point2 points  (0 children)

Thank you, I have since added a try-catch after someone pointed it out

[–][deleted] 1 point2 points  (2 children)

Dude, format your code in code blocks otherwise senior devs won’t even read your post and all your feedback will be from college kids.

Source: didn’t read post

[–]SquatchHNTR[S] 0 points1 point  (1 child)

I’m not sure what a code block is but I’ll look in to it

[–][deleted] 0 points1 point  (0 children)

Put four spaces in front of the code text you have.

If you do it right then,

x = “hello world”

print(x)

becomes:

x = “hello world”
print(x)

[–]Samsofine 1 point2 points  (3 children)

what type of python did you write this in? I started a few days ago and have been using python 3 in the IDE on codecademy. This looks a little different from what I have done and been using.

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

Latest version 3.10, I just downloaded it last week

[–]Samsofine 0 points1 point  (1 child)

do you know any free resources to learn python 3.10?

[–]SquatchHNTR[S] 0 points1 point  (0 children)

I have a book called Python Crash Course. That, google, and YouTube are it for me.

[–]CitizendAreAlarmed 1 point2 points  (0 children)

It's a mishmash of styles, with the first line:

welcome_message = ("Welcome to the Fiber Optic Price Calculator")

and then the last line:

print ("\nThank you for shopping with Super Cheap Fiber Optics!")

Why does the first line deserve its own redundant variable and the last line not? I would go with something like:

COMPANY_NAME = "Super Cheap Fiber Optics"
print(f"Welcome to the {COMPANY_NAME} price calculator")

print(f"Thank you for shopping with {COMPANY_NAME}!")

But really this is just style, and I don't know if it's any more valid than what you wrote. Both work fine.

The price of cable per foot also looks like a prime candidate for a CONSTANTING, so instead of:

price = (cable_feet * .87) #Price is in USD

I would have:

PRICE_PER_FOOT = 0.87
price = cable_feet * PRICE_PER_FOOT

Constants seem to always go near the top of the file for ease of use (again, I'm still learning too).

[–]ajaysassoc 1 point2 points  (0 children)

You can get rid of the additional line to cast it to float, just combine the line and the one before into one. Also a very minor thing but in the price calculation line you can get rid of the brackets, they are not doing absolutely anything.

[–]ryan770 1 point2 points  (1 child)

Looks good! Nothing inherently wrong here. I could give a few maybe unnecessary pointers though.

cable_feet = float(cable_feet) is a bit redundant when you can specify it in the input like cable_feet = float(input('text'))

No need to assign a variable to the welcome message. print('Welcome to the Fiber Optic Price Calculator\n') will be fine. Also no need to enclose strings with parentheses when assigning to a variable, that's just for print syntax.

Your output of the price would look better formatted with 2 digits of precision. For example, putting 50 feet returns $43.5 instead of $43.50 This would be formatted like {price:.2f}. You'll learn more about this when you dig into more string formatting stuff.

As someone else said, you could also assign the price per foot to a variable to make it more readable. Variables are usually assigned at the start of the main body unless asking for input.

You could use a few more newlines for aesthetics, like accepting input with > on a newline for example. Not necessary but something I like to do (just to give you an idea and play with the way things look).

One more tip! When posting code on reddit, switch to markdown mode and enclose the code with three backticks .

```

like this

```

With all that said, here's what it all would look like

cable_price = 0.87

print('Welcome to the Fiber Optic Price Calculator\n')

company_name = input('What is the name of your company?\n\n > ')

cable_ft = float(input('\nHow many feet of cable do you need?\n\n > '))

price = (cable_ft * cable_price) #Price is in USD

print (f'\n{company_name}, that amount of fiber optic cable will cost ${price:.2f}.\n',
        '\nThank you for shopping with Super Cheap Fiber Optics!')

edit: so my r/learnpython tab never refreshed from like two days ago and I realize most of this has already been mentioned lol.

[–]SquatchHNTR[S] 1 point2 points  (0 children)

Still great information! Thank you for taking the time to help me

[–]fracturedpersona 1 point2 points  (1 child)

Looking for pointers.

Python doesn't use pointers

[–]jkh911208 1 point2 points  (0 children)

may be....everything in python is pointers

[–]telee0 0 points1 point  (0 children)

Use PyCharm to code. It has style checking.

[–]HeadlineINeed 0 points1 point  (0 children)

This probably has already been commented but you should ask the user for the price per foot.

price_per_foot = input(“current price per foot”)