Python has two kinds of numbers. An int is a whole number: 4, -12, 5400000. A float is a number with a decimal point: 4.0, 12.5, -0.25.
The basic arithmetic operators are +, -, * (multiplication), and / (division):
price = 12.5
tickets = 4
total = price * tickets
print(total)
Output:
50.0
Division with / always produces a float, even when the result is a whole number:
print(10 / 2)
Output:
5.0
Operators follow the usual order of operations: * and / before + and -. Parentheses override the order:
print(2 + 3 * 4)
print((2 + 3) * 4)
Output:
14
20
ticket_price holding 12.5.tickets holding 4.total by multiplying the two variables. Do not write 50.0 directly.remaining holding 100 - total.total and remaining.Run your code to see the output, then press Submit.
import unittest
class TestNumbers(unittest.TestCase):
def test_ticket_price_is_12_point_5(self):
self.assertEqual(ticket_price, 12.5)
def test_tickets_is_4(self):
self.assertEqual(tickets, 4)
def test_total_is_50(self):
self.assertEqual(total, 50.0)
def test_remaining_is_50(self):
self.assertEqual(remaining, 50.0)
ticket_price = 12.5 tickets = 4 total = ticket_price * tickets remaining = 100 - total print(total) print(remaining)
Sign in to join the discussion.
No comments yet. Be the first to ask a question.
Press Run to execute your code, or Submit to test and complete this problem.