Monday, February 04, 2019

Exercises for Programmers: 57 Challenges to Develop Your Coding Skills - Chapter 1

Chapter 1, the most basic option for a tip calculator using Python.  No type checking and no error handling.

print("Enter a tip:")
x =input()
print("Tip is: " + str(x))
print("Enter a bill/total: ")
y = input()
print("Bill is: " + str(y))

print("Tip is: " + str(y * x/100))
print("Total is: " + str(y + (y * x/100)))


  • Step 2: round up the tip to the cent and the total to the cent.
  • Step 3: restrict the user to numbers for the bill and tip %.
  • Step 4: if the input isn't a number/%, ask them to try again or bail.
  • Step 5: no negatives
  • Step 6: use functions
  • Step 7: make it a gui (well, that's not going to happen in Python....maybe use Javascript) - use a slider, not a prompt.  Could use Visual Studio/C# as well, although that's got overhead.

No comments: