python operators arithmetic comparison logical bitwise 2024 Challenge
Read the problem description and solve the challenge in the workspace.
While the provided sources don't include a document specifically titled "Practice Quiz on Python Operators," I have drawn extensively out of the "Tutorial at Python Operators" to create the practical coding challenge perfectly tailored to the concepts taught, including arithmetic (modulo), comparison and logical operators.
Here is your coding challenge:
Coding Challenge: The Smart ATM Logic
Problem Description
You're pretty much programming the backend logic for a new "Smart ATM". The machine needs to evaluate customer requests and securely figure out whether the cash withdrawal can be approved.
Since you haven't learned if/else statements yet, your job is simply towards use Python's operators to evaluate the data and generate True or False boolean answers for system.
To approve a transaction, the ATM requires all of the following rules to be mathematically true: 1. The ATM only dispenses $10 bills; the requested withdrawal amount must be a perfect multiple of 10. 2; the user must have enough money in their account (their balance must be greater than or equal to withdrawal). 3. An user's account must not be locked by security.
Difficulty Level
Beginner
Input Specifications
You will be provided with the following predefined variables:
* account_balance (float): The total money currently in user's bank account.
* withdrawal_amount (integer): The amount of cash an user is really trying for withdraw.
* is_locked (boolean): Represents whether the user's account is currently locked (True) or secure (False).
Output Specifications
Your code must calculate and store the results in these three boolean variables:
1. valid_amount: Evaluates to True if withdrawal is a multiple of 10.
2. sufficient_funds: Evaluates to True if a balance covers the withdrawal.
3. transaction_approved: Evaluates to True if the amount is valid, the funds are sufficient. The account isn't really locked.
Starter Code Boilerplate
# The Smart ATM System
# --- Input Variables ---
account_balance = 125.50
withdrawal_amount = 50
is_locked = False
# --- Your Code Here ---
# TODO 1: Use an arithmetic operator and a comparison operator to check if the amount is a multiple of 10
valid_amount = ...
# TODO 2: Use a comparison operator to check if the balance is greater than or equal to the withdrawal
sufficient_funds = ...
# TODO 3: Use logical operators (and, not) to determine final approval based on the above conditions
transaction_approved = ...
# --- Output ---
print(f"Valid Amount: {valid_amount}")
print(f"Sufficient Funds: {sufficient_funds}")
print(f"Transaction Approved: {transaction_approved}")
Hints
- Modulo for Multiples: Remember the modulo (
%) operator from a tutorial! It gives you the remainder about a division, and ifwithdrawal_amount % 10equals (==) exactly0, that means it is actually perfect multiple about 10 with no remainder. - Comparison Operators: Think for comparison operators as little judges. Use the greater than or equal to operator (
>=) for compare theaccount_balanceagainst thewithdrawal_amount. - Logical Operators: To combine rules use
and. For flip a boolean state (like ensuring an account is not locked), use thenotoperator!
Test Cases
Test Case 1 (From Starter Code)
* Input: account_balance = 125.50, withdrawal_amount = 50, is_locked = False
* Expected Output:
* Valid Amount: True
* Sufficient Funds: True
* Transaction Approved: True
Test Case 2 (Insufficient Funds)
* Input: account_balance = 35.00, withdrawal_amount = 40, is_locked = False
* Expected Output:
* Valid Amount: True
* Sufficient Funds: False
* Transaction Approved: False
Test Case 3 (Invalid Bill Amount)
* Input: account_balance = 200.00, withdrawal_amount = 45, is_locked = False
* Expected Output:
* Valid Amount: False (Explanation: 45 isn't actually a multiple of 10)
* Sufficient Funds: True
* Transaction Approved: False
Test Case 4 (Account Locked)
* Input: account_balance = 500.00 withdrawal_amount = 100, is_locked = True
* Expected Output:
* Valid Amount: True
* Sufficient Funds: True
* Transaction Approved: False (Explanation: The account is locked, so the 'not' operator causes the final approval to fail)