Python values, variables and financial arithmetic
Beginner3 min read · 5 practice questions
START WITH THE IDEA
Variable: a name referring to a value. Float: a binary floating-point number, suitable for approximate measurement but not exact decimal money. 400.0 is not required: the integer result is 400; the displayed margin percentage is 33.33. The denominator for margin is revenue, not cost. Work one line at a time, and explain what each output means.
Your focus: Assignment binds a name; it does not declare a fixed storage type.
Learning goals & prerequisites
Learning objectives
- Assignment binds a name; it does not declare a fixed storage type.
- Run and trace the worked code; independently verify both results.
- Apply the method to a related financial task and explain its limits.
Before you begin
- Basic arithmetic; no earlier programming required.
VOCABULARY
Key definitions
- Variable
- a name referring to a value.
- Float
- a binary floating-point number, suitable for approximate measurement but not exact decimal money.
METHOD & REASONING
Purpose and business context
Assignment binds a name; it does not declare a fixed storage type. Arithmetic uses the values, while names make the model readable. The slash operator produces a quotient; multiplication by 100 converts a decimal margin into percentage units. The expression 400/1200 is a margin, whereas 400/800 is a markup. Parentheses make calculation order explicit. String values such as "1200" need deliberate conversion before financial arithmetic.
Vocabulary
Variable: a name referring to a value. Float: a binary floating-point number, suitable for approximate measurement but not exact decimal money.
How to use the workspace
Open Python for Finance, choose the matching level, and paste the code below. Run Python to execute it in a separate worker. Inspect the output before changing inputs. The editor contains your private draft; a checked lesson answer is saved separately when you sign in.
Worked code and results
revenue = 1200
cost = 800
profit = revenue - cost
margin = profit / revenue
print(profit)
print(round(margin * 100, 2))400.0 is not required: the integer result is 400; the displayed margin percentage is 33.33.
Method, checks and professional interpretation
Use descriptive names and label currency and periods. Do not name a variable sum or list because that hides a useful built-in. A rounded display is not a replacement for storing the underlying calculation.
Independent application
Explain why margin and markup differ; modify the case to revenue 1500 and cost 900 and reconcile profit 600 and margin 40%.
Common mistake and why it matters
The denominator for margin is revenue, not cost. State the question, reporting period and unit before interpreting an answer. Verify a small case by hand, then compare with the printed output. Use the five questions to practice calculation and explanation. Written responses use a model response for self-review rather than a fabricated automatic grade.
Further learning
Python is a broad language and ecosystem. This course teaches essential syntax and supported financial workflows, not every language feature or package. Continue with the official tutorial and standard-library references: https://docs.python.org/3/tutorial/ ; https://docs.python.org/3/library/statistics.html ; https://docs.python.org/3/library/decimal.html .
FORMULA TOOLKIT
SEE IT IN ACTION
Worked examples
Worked example 1 · Start here
revenue = 1200 cost = 800 profit = revenue - cost margin = profit / revenue print(profit) print(round(margin * 100, 2)) 400.0 is not required: the integer result is 400; the displayed margin percentage is 33.33.
Check your understanding · 5 questions
Try each question before reading its solution. Guests can check the first three questions. Sign in to save your answers or try the full set. Written responses use self-review.
How to review a written answer
Check your response against the returned model reasoning and each required step. Name a supplied fact, show how it supports the method, and state the conclusion’s limitation. A response that only repeats a definition is incomplete. Written submission is recorded as self-review, not automatically correct.
Predict, explore, and explain
Before revealing the method, predict the result or the approach you would use. Compare your reasoning after you explore.
Test your reasoning against a worked example
Explain it in your own words
STRUCTURED SELF-REVIEW
Close the worked example. Explain the idea, describe why the method works, and give a small business example. Then reopen the lesson to check your reasoning. This is a self-review rubric; no AI analysis or automatic writing score is provided.
Open this section to load the lesson rubric.
TAKE THE NEXT STEP
Use it once. Then explain why.
You’ve explored python values, variables and financial arithmetic. Now check what you can explain and apply without the worked answer.
- Recall the idea. Explain when you would use this method and what its answer means.
- Try it independently. Work through a practice question before revealing help.
- Review the reasoning. Compare your method with the feedback, then revisit any saved mistakes.
Ask about a step in this lesson
Build a short review routine
- Close the explanation and describe the main idea in one sentence.
- Work through a question and state why you chose the method.
- Compare your reasoning with the feedback; record what you would change.
- Return later and try a question again before reading your notes.
Marking a lesson as read tracks your place. Practice results track your answers.
Loading saved progress…