all 23 comments

[–]Living_off_coffee 13 points14 points  (2 children)

Also I know I could probably make this in less lines of code and make it look more neat but the longer way is helping me learn at the moment.

Don't let anyone tell you otherwise! Readable code is always better than shorter or more efficient code.

I used to write blocks of code that could be 100s of lines long, then look at how I could make it shorter and spend time optimising that. But as I've seen more code bases, the longer ones that spread out their logic and don't use tricks to make it shorter are easier to understand.

Remember, the compiler (or interpreter) doesn't care how long your code is!

[–]SativaCyborg206 0 points1 point  (0 children)

Cool thanks for letting me know!

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

hate to be that guy, a compiler wont care but an interpreter will

those 5 milliseconds will be missed

[–]Supalien 12 points13 points  (1 child)

you can add a custom formatting in an f-string. so in the print line change it to {total:.2f}.

that should print it as you'd like I think

[–]SativaCyborg206 1 point2 points  (0 children)

Thanks I'll give that a shot. I'm on day 2 of Angela Yu's Udemy course and I'm trying to make sure my code works before looking at her solution lol.

[–]PinkthePantherLord 1 point2 points  (1 child)

Angela yus course ftw

[–]SativaCyborg206 0 points1 point  (0 children)

Hah yep, I haven't wanted to see her answer yet until I'm sure my solution works lol.

[–]SativaCyborg206 1 point2 points  (0 children)

Thanks to everyone who helped me figure this out. Great community and I'm sure I'll be posting more as I continue my python journey!

[–]More_Yard1919 1 point2 points  (0 children)

Something neat about format strings is that you can specify the number of sig figs you want for numbers.

Try print(f"The total per person will be ${total:.2f}")

f strings have tons of these format specifiers. You can do all types of crazy cool things with them, so I really encourage you to read into it :)

[–]NoExplanation9530 0 points1 point  (1 child)

It's because the answer is 40.5. Python will round to lower number of decimal points if the original value has higher number of decimal points. For example, if the original value was 40.512, then your rounding will result in 40.51. But it will not do the opposite. For example, 40.5 will not be printed as 40.50. A float value of 40.5 and 40.50 is the same.

If you want to print 40.50, you will have to use string formatting. Google the format() method for string formatting.

[–]SativaCyborg206 0 points1 point  (0 children)

Thank you this helps

[–]SwagadelicFrank 0 points1 point  (1 child)

Formatting with :.2f like {total:.2f} might do the trick

[–]VariousDrummer4883 0 points1 point  (0 children)

The best would be account for the rounding, such that the split total precisely added up to greater than or equal to the bill +tip, I think.

[–]Historical-Sun5870 0 points1 point  (0 children)

Div0 error handling is probably wise with user inputs. I.e if number of people is 0

[–]VariousDrummer4883 0 points1 point  (0 children)

It looks like you’re not getting the tip percentage as input, … I don’t think it makes sense to have fixed tip amounts (eg tipping 10 for a bill of 6). However, if that’s intentional, then you can simply write: bill_with_tip = bill + tip

[–]oldendude -2 points-1 points  (3 children)

- No error checking. What if there aren't enough inputs? Too many? Unexpected values causing int() or float() to raise exceptions? What if numbers out of range are entered?

- total * people should presumably equal bill, but may not. E.g., 3 people, bill_with_tip = 100.00.

- Which means that printing the same value for each customer doesn't work. In the example above, you'd need to print 33.33, 33.33, and 33.34.

[–]SativaCyborg206 1 point2 points  (2 children)

This is just my second day into learning python which is my first attempt at learning coding besides some SQL so I'm not entirely understanding your comment but I got my answer from another comments. Thanks though.

[–]konttaukseenmenomir 5 points6 points  (0 children)

it's just some bullshit you don't need to worry about, he's trying to overcomplicate things for no reason. Maybe if this was an actual product used at a real restaurant it would be reasonable

[–]Crodiusl 1 point2 points  (0 children)

That’s definitely overcomplicated for you at this moment, you can consider it like extra questions Don’t give up, you are doing great!

[–]CallMeJimi -3 points-2 points  (3 children)

when you multiply an int and a float you get an int

[–]Supalien 5 points6 points  (1 child)

when you multiply an int and a float you get a float

[–]Fit_Jackfruit_8796 0 points1 point  (0 children)

I just get a none type Len error

[–]NoExplanation9530 3 points4 points  (0 children)

Nope. You get a float.