The bus card holds balance and this ride costs fare. Write Pay(balance, fare) to return what's left and nil if there's enough, or 0 and the error "not enough money" if not. Make the error with errors.New, and remember to import errors first.
Pay(20, 3)→(17, None)Pay(2, 3)→(0, 'not enough money')func Pay(balance, fare int) (int, error)package main
// your code here: import "errors"
func Pay(balance, fare int) (int, error) {
if balance < fare {
// your code here: return 0 and the error "not enough money"
}
return balance - fare, nil
}
Run tries the examples. When they look right, Submit.