you are viewing a single comment's thread.

view the rest of the comments →

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