Overall this is pretty impressive for someone just starting out - well done!
Here's a few overall design comments. I'll include technical feedback as
comments directly in Updated-PythonPractice.py
When coding you don't want to write the same piece of functionality twice. In longer programs this type of duplication makes it hard to follow the flow of the program, and it also creates situations where it's really hard to track down bugs. You think you've fixed it here, but you've got the same issue over there 100 lines down the page...
In your Original-PythonPractice.py
you can avoid this by taking lines 6-14, and 31-39 outside of your if
statment (see Updated-PythonPractice.py
for an example of this). A side benefit is that you end up with less code, and less code is usually simplier and easier to understand :)
Most of your variable names are good except for y
and z
. You want your variables to describe what they are so that when you come across them 100 lines down the page, or in 6 months time when you need to update the program, it's easy to understand what they're doing. y
and z
don't tell me anything.
In Updated-PythonPractice.py
I've changed these to daily_hours
and days_per_week
. This also makes the maths that calculates the weekly salary a lot more readable.
What happens if someone types Yes
to your first question? Probably not the result you want... Have a look at the code and try to work it out before running it to see.
There's several ways you could tighten this up, but the easiest is probably changing the else
on line 30 of Original-PythonPractice.py
to an elif ...
.
(Bonus points if you add a little code that checks if the user's input matches the A
or B
you're expecting. If not, show them a helpful message and ask again.)
If you want to include multiline strings in Python you can use triple quotes: '''
or """
. These also work with f-strings
. See line 4 of Updated-PythonPractice.py
for an example.
In your tax elif
logic what happens if, for example, a resident's income works out to be $18,000.50? How can you fix these statements?