C. Subtracting a string from an integer causes a type error
D. The new_balance variable is unused
Solution
Step 1: Identify data types involved
balance is an integer, expense is a string representing a number.
Step 2: Understand subtraction operation rules
Subtracting a string from an integer is invalid and causes a type error in most languages.
Final Answer:
Subtracting a string from an integer causes a type error -> Option C
Quick Check:
Type mismatch in subtraction = Error [OK]
Hint: Check data types before arithmetic operations [OK]
Common Mistakes:
Ignoring type mismatch errors
Assuming variables are uninitialized
Confusing addition and subtraction
5. Splitwise wants to test a complex scenario where multiple users owe each other different amounts. Which approach best ensures the financial logic is tested correctly?
hard
A. Skip tests and rely on manual checks
B. Test only single user transactions repeatedly
C. Test UI elements without checking calculations
D. Create test cases with multiple users, set debts, perform calculations, and verify final balances
Solution
Step 1: Understand the need for realistic test scenarios
Testing multiple users with debts simulates real app usage and catches complex bugs.
Step 2: Verify calculations and final balances
Performing calculations and verifying results ensures the financial logic works end-to-end.
Final Answer:
Create test cases with multiple users, set debts, perform calculations, and verify final balances -> Option D
Quick Check:
Realistic multi-user tests = Accurate financial logic [OK]
Hint: Test real-world scenarios with multiple users [OK]