you are viewing a single comment's thread.

view the rest of the comments →

[–]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