# Carpet cost Calculate the cost of a carpet.

## Try

Select the button below to open the Python program in a new window. Run the program and read the lines of code to see if you can understand how it works. It will be helpful to arrange your display so that you can have this browser window on one side of the screen and the code on the other.

Watch this video to learn about the new concepts shown in the program:

## Investigate Explain the purpose of the int command in lines 15, 16 and 17.

“int” is a function that converts the input from the keyboard that will always be text, known as a “string” into a whole number, known as an “integer” so that it can be used for mathematical calculations. This is known as “casting”. Explain why a subprogram was used in lines 6-10 instead of writing the code from line 19 onwards.

Breaking a program down into subprograms is called decomposition. It makes it easier to write different parts of the program a step at a time. It is easier to read the code. It allows a section of code to be resused more easily.

The cost of the grippers are 50p per metre around the perimeter of the room which is why we can add the length to the width to calculater their total price.

## Make

### Success Criteria

Change the program below so that it:

1. Includes the cost of an underlay (the soft cushion underneath the carpet). This is calculated as the width multiplied by the length multiplied by £2.

#### Typical inputs and outputs from the program would be:

Enter the width of the room to nearest meter: 2

Enter the length of the room to nearest meter: 3

Enter the price of the carpet per m2: 2

The total cost is: £ 79.0

#### Knowledge Organiser

Use these resources to learn about new commands for this level and to help you meet the success criteria.

###### Notes:

x = int(y)

Casts (changes) the string y into an integer x. Integers are whole numbers, positive, negative or zero.

x = float(y)

Casts (changes) y into a decimal x. Decimals are also called floats or real numbers.

x = input(y)

Assigns x to be an input from the keyboard using prompt y.

return x

Returns the value x from a subprogram so that it can be used elsewhere in the program.

Mathematical operators: + add – subtract * multiply / divide.

The concatenator `,` joins strings and variables into a single output. E.g. `print(“Hello”, “World”)` You can also use `+` if you don’t want a space between each piece of data.

## Evaluate

Run the unit tests below to check that your program has met the success criteria.

Width of the room: 2

Length of the room: 3

Price of the carpet: 2

The total cost is: £ 79.0

In partnership with  