You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All variables that are assigned `None` point to the same object. New instances of `None` are not created, that is `None` by nature is of type Singleton.
2
+
3
+
Example, when you assign 2 variables with `None`, both point to the same object.
4
+
5
+
```python
6
+
a =None
7
+
b =None
8
+
a == b
9
+
#=> True
10
+
```
11
+
12
+
Python will also return `None` from a function that doesn't already have a stated `return` value, making it easy to check if the function completed without errors.
13
+
14
+
```python
15
+
deftest_func():
16
+
pass
17
+
test_func()
18
+
#=> returns None
19
+
20
+
deftest_func2():
21
+
return
22
+
#=> returns None
23
+
```
24
+
25
+
The `None` Object is a singleton of class `NoneType`. So when you find the type of a variable which is assigned with `None` it will always be of type `NoneType`.
26
+
27
+
```python
28
+
a =None
29
+
type(a)
30
+
#=> <class 'NoneType'>
31
+
```
32
+
33
+
When you toggle a variable between a value and `None`, what basically happens is a reset of the variable.
34
+
35
+
```python
36
+
37
+
a = [] #=> Variable 'a' is pointing to a list
38
+
39
+
a =None#=> Variable 'a' is reset to an empty state. the value of a is now absent.
- In Python, `None` is frequently used as a placeholder to represent the **absence of a value** for a variable, object, or argument.
4
+
5
+
## 1. Make New Seating Chart
6
+
7
+
Remember, you will need to create an empty dictionary first. Next, fill the dictionary _keys_ with however many seats are available and set their _values_ to a **placeholder** to indicate that they are available but unassigned.
8
+
9
+
## 2. Arrange Reservations
10
+
11
+
- If there isn't a guest list, you will want to return a `new_seating_chart()` filled with placeholders. A `default argument` for your function might be helpful here. If you do have a guest list, you can start with a `new_seating_chart()`, then loop from 1 to the number of guests and assign them to seats in order.
12
+
13
+
## 3. Find all Available Seats
14
+
15
+
- You can loop through all the (key, value) pairs in a dictionary by calling `dict.items()`. You can verify that a variable or value is None through an `if statement` -- `if var is None` will return True if the value is `None`. You can add things to a `list` by calling `list.append()`
16
+
17
+
## 4. Current seating capacity
18
+
19
+
- You can loop through all of the values in the dict object by calling `dict.values()`. Seats are available when their value is `None`.
20
+
21
+
## 5. Accommodate Waiting Guests
22
+
23
+
- You need to find the current number of empty seats and check to see if it is greater than or equal to the number of guests waiting. If the guests can be accommodated, you will need to call `find_all_available_seats()` to get a list of seat numbers you can assign guests to. Remember that `range()` can take any sort of number as an argument....**including** the number returned from calling `len()` on a list. Also remember that using `list[index_number]` will return the **value** that is located at the **index number** inside the brackets.
24
+
25
+
## 6. Empty the Seats
26
+
27
+
- Given the seating chart `dict`, and a `list` of seat numbers, you'll want to indicate the seat is now available for another guest by replacing their name with a placeholder. Looping through the seat number list and looking for those seats in the dictionary might be helpful here.
You are the Maître D' of a hotel restaurant. Your task is to manage the seating arrangements for the dining room according to the number of seats available today, number of reservations, and the "walk in" guests currently waiting to be seated. For the purposes of this exercise, seating is assigned by first available empty seat.
4
+
5
+
You have 6 different dining room organization challenges to complete.
6
+
7
+
## 1. Make Today's Seating Chart
8
+
9
+
Define the `new_seating_chart()` function that takes a size argument representing the number of seats that will be set in the dining room today. If no `size` is given, the function should return a seating chart with 22 seats. Seat values should have a placeholder of `None` to indicate they are available to assign to a guest.
10
+
11
+
## 2. Arrange Reservations
12
+
13
+
Define the `arrange_reservations()` function with 1 parameter for a list of guest names. This represents the number of people who've reserved places in the dining room today.
14
+
15
+
This function should return a `dict` seating chart of default size (22 seats), with guests assigned to seats in the order they appear on the reservation list. All unassigned seats should be set to `None`. If there are no guests, an "empty" seating chart with all `None` placeholders should be returned.
Define the `find_all_available_seats(seats)` function that takes 1 parameter (_a seating chart dictionary_) and returns a `list` of seat numbers that are available for guests that are currently waiting.
25
+
If a seat is empty, It will be of `None` value in the dictionary. Occupied seats will have the name of the guest.
Define the `accommodate_waiting_guests(seats, guests)` function that takes two parameters. The first parameter will be a seating chart `dict`. The second parameter will be a `list` of guests who have "walked in" unexpectedly.
49
+
You'll first need to find out how many seats are available and whether or not you can even give the unannounced guests seats at this time.
50
+
51
+
If you do not have enough seats, return `False`.
52
+
53
+
If seats are available, you will want to give the guests places on the seating chart, and return it updated.
54
+
Tip: You can use previously defined functions to do the calculations for you.
Define the `empty_seats()` function that takes two parameters. The first parameter will be a seating chart dictionary. The second parameter is a list of seat numbers you need to "free up" or empty -- that is, you need to assign the seat number value to `None`.
68
+
69
+
Return the `dict` of seats sent as the parameter after updating the empty seat values.
In Python, `None` is frequently used to represent the absence of a value -- a placeholder to define a `null` (empty) variable, object, or argument.
2
+
3
+
If you've heard about or used a `NULL` or `nil` type in another programming language, then this usage of `None` in Python will be familiar to you. `None` helps you to declare variables or function arguments that you don't yet have values for. These can then be re-assigned to specific values later as needed.
4
+
5
+
```python
6
+
a =None
7
+
print(a)
8
+
#=> None
9
+
type(a)
10
+
#=> <class 'NoneType'>
11
+
12
+
# Adding a Default Argument with `None`
13
+
defadd_to_todos(new_task, todo_list=None):
14
+
if todo_list isNone:
15
+
todo_list = []
16
+
todo_list.append(new_task)
17
+
return todo_list
18
+
19
+
```
20
+
21
+
`None` will evaluate to `False` when used in a conditional check, so it is useful for validating the "presence of" or "absence of" a value - _any_ value -- a pattern frequently used when a function or process might hand back an error object or message.
22
+
23
+
```python
24
+
a =None
25
+
if a: #=> a will be evaluated to False when its used in a conditional check.
0 commit comments