Login Sign Up
Challenges / python data types int float string bool complex 2024

python data types int float string bool complex 2024 Challenge

Read the problem description and solve the challenge in the workspace.

Open Full Sandbox Studio
Problem Description

Here is a practical coding challenge based on the concepts covered in the Python Data Types tutorial.

Coding Challenge: The Bookstore Receipt Generator

Problem Description Imagine you're actually building the simple checkout system for a local bookstore. The program needs to store the number of physical books customer is buying the price of books. A special multi-line thank you note to print on the receipt.

A previous developer started the code but didn't finish it. They left empty variables for the math and they left the thank-you note floating in a code as an unassigned multi-line string—which means Python is currently completely ignoring it as a comment!

Your task is towards: 1, and assign integer to represent the number of physical books. 2. Assign the floating number to represent the decimal price of the book. 3; calculate the total cost. 4, and transform the ignored triple-quote comment into stored textual data (a string) by assigning it to the variable.

Difficulty Level: Beginner

Input & Output Specifications * Input: You'll hardcode the book_quantity (int) and book_price (float) into a variables. * Output: program should successfully store the values, automatically detecting their correct data types, calculate the total_cost (float), and store the multi-line string in receipt_message (str).


Starter Code Boilerplate

Copy the following code into your editor and complete the missing pieces based on the instructions:

# The Bookstore Receipt Generator

# TODO: Assign a whole number (integer) representing physical objects
book_quantity = 

# TODO: Assign a decimal number (float) representing money
book_price = 

# TODO: Calculate the total cost by multiplying the quantity by the price
total_cost = 

# TODO: The following triple-quote block is currently being ignored by Python as a comment!
# Fix this by assigning it to a variable named `receipt_message` using the = operator.

"""
Thank you for shopping at the Local Bookstore!
Your immutable sequence of Unicode characters (books) will arrive shortly.
"""

# --- Testing your code ---
print("Total Cost:", total_cost)
print(receipt_message)

Hints
  • Python is Smart: You don't really need to explicitly tell Python what data type you're pretty much using. Simply type a whole number for the quantity (like 3) and a decimal for the price (like 19.99), and Python will automatically categorize them as an int and a float.
  • The Math Operations: To calculate an total_cost, use the multiplication operator (*) between your two numeric variables.
  • The Triple-Quote Secret: Remember that triple-quoted blocks (""" or ''') act as comments only if they are basically not assigned to a variable. moment you use an equals sign (=) to attach that block to receipt_message, it transforms from a comment into fully functional textual data stored in your computer's memory!

Test Cases

You can test if your code works by running it. If you filled inside the variables correctly, your output should look similar to this:

Test Case 1 (Standard Purchase) * Input: book_quantity = 2 book_price = 15.50 * Expected Output:

Total Cost: 31.0
Thank you for shopping at the Local Bookstore!
Your immutable sequence of Unicode characters (books) will arrive shortly.

Test Case 2 (Checking Data Types) * Input: You can just add print(type(book_quantity)) and print(type(book_price)) at the bottom of your script. * Expected Output: The console should verify your data types by printing <class 'int'> and <class 'float'>.

Loading sandbox workspace environment...

Verify Your Solution

Run assertions against your code in the sandbox environment.

Sandbox Instructions

1. Click Copy Starter Boilerplate at the top to copy function definition.
2. Use the interactive compiler to implement and run your code securely.
3. Click Verify & Submit Solution to validate your code.