Commit e3a12857 authored by Swicech's avatar Swicech
Browse files

Upload assignment 1

parents
%% Cell type:markdown id: tags:
# Baking course
**Learning goals:**
- Pretty-printing text
- Performing simple computations
**Starting Out with Python:**
- Chapter. 2.3
- Chapter. 2.8
- Chapter. 8
In this assignment you will compute the amount of ingredients required to make cookies and print the result prettily to the screen.
You are making cookies, and you have a recipe which yields 48 cookies. The recipe requires the following ingredients:
- 400g sugar
- 320g butter
- 500g chocolate
- 2 eggs
- 460g flour
%% Cell type:markdown id: tags:
## a)
%% Cell type:markdown id: tags:
Ask the user about how many cookies they want to make, and output how many ingredients are required to make that amount of cookies
Example run:
```python
How many cookies do you wish to make? 24
Number of cookies: 24
Sugar (g): 200.0
Butter (g): 160.0
Choocolate (g): 250.0
Egg: 1.0
Flour (g): 230.0
```
***Write the code in the block below***
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
#### Hint for task a: Escape Character
%% Cell type:markdown id: tags:
`\n` is useful for forcing a new line! Example: `print(“hei\npå\ndeg”)` outputs
**print**
```
hei
deg
```
%% Cell type:markdown id: tags:
## b)
%% Cell type:markdown id: tags:
Ask the user about how many cookies they want to make three times and print the ingredients in an elegant way (read: columns aligned correctly using spaces). You only need to print the number of cookies, as well as how much chocolate and sugar is needed. See the following example:
```python
How many cookies do you want to make? 24
How many cookies do you want to make now?
Lastly, how mny cookies do you want to make now? 72
Number of cookies: sugar (g) chocolate (g)
24 200.0 250.0
48 400.0 500.0
72 600.0 750.0
```
`rjust()` og `ljust()` are useful functions here, but to use them you need to convert the number of cookies to a string using str().
***Write the code in the block below.***
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
#### `ljust()` and `rjust()`
%% Cell type:markdown id: tags:
`streng.ljust(width)` tring.ljust(width) returns the string left justified in a string of length width. s strengen "left justified" i en streng av lengde width. streng.rjust(width) does the same, except the string is "right justified". For example `print('hei'.rjust(15))` outputs:
```python
hei #text is printed after 12 white spaces as the string itself is 3 characters long.
```
Read more about `rjust()` og `ljust()` [here](https://docs.python.org/2/library/stdtypes.html?highlight=rjust#str.rjust).
%% Cell type:code id: tags:
``` python
```