I've been working through some problems in a CS50P course and recently got stuck on one. I spent a couple of hours trying to figure it out without relying on Google, just using Python documentation. The problem involves calculating tips based on meal costs. I created two functions: `dollars_to_float` and `percent_to_float`, to convert inputs into float values after removing the dollar sign and percent sign respectively. However, I'm uncertain if I correctly implemented these conversions. Here's the initial solution I crafted, and I've got some feedback indicating I might be processing the strings incorrectly. I would love any thoughts on whether my approach aligns with how the problem should be solved. Thanks for your time!
2 Answers
Your approach is actually off target a bit. The problem is designed so that you should pass the entire strings, like '$50.03' and '15%', into your `dollars_to_float` and `percent_to_float` functions respectively. Instead of removing the '$' and '%' before passing them, handle that inside the functions. Also, about the line `p/100`, just calling it without reassigning or returning it does nothing, so watch out for that!
Got it, I'll keep reworking my functions to fall in line with the prompt. Appreciate it!
It looks like your initial instinct was right to remove the symbols before converting to float. However, the instructions were clear that the full strings should be passed to the functions, so you should reconsider where you're doing that. As for the line where you didn't assign `p/100`, it doesn't do anything as you noted. Your earlier method of handling inputs was way more straightforward!
That makes sense! I was just overcomplicating things. Thanks for the tip!
Yeah, I see where I went wrong. I appreciate the advice!

Thanks for clarifying! I see now that sticking to the original function structure is key.