Skip to main content

Practice Yaml

Updated Dec 12, 2020 ·

Overview

Note that these are not the exact same questions. You can try to answer them and create a YAML file in your own machines based on the questions.

Use the expandable answers to compare your solution after you finish each exercise.

1. Create a dictionary with the following key-value pairs

KeyValue
nameapple
colorred
weight90 g
Answer
name: apple
color: red
weight: 90 g

2. Create the dictionary for "employee" using the data below.

KeyValue
namejane doe
genderfemale
age24
Answer
employee:
name: jane doe
gender: female
age: 24

3. Using the same dictionary above, add the "address" to the "employee" dictionary:

employee:
name: jane doe
gender: female
age: 24

The details for the address are:

KeyValue
cityorlando
stateflorida
countryunited states
Answer
employee:
name: jane doe
gender: female
age: 24
address:
city: orlando
state: florida
country: united states

4. Create an array of 4 apples and 2 mangoes.

Answer
- apple
- apple
- apple
- apple
- mango
- mango

5. Create a list of fruits with their attributes based on the table below.

FruitColorWeight
applered90 g
bananayellow100 g
melonsgreen150 g
apricotsorange75 g

The first one is already created.

- fruit: apple
color: red
weight: 90 g
Answer
- fruit: apple
color: red
weight: 90 g

- fruit: banana
color: yellow
weight: 100 g

- fruit: melons
color: green
weight: 150 g

- fruit: apricots
color: orange
weight: 75 g

6. Using the same dictionary from Question 3, add another employee named 'John Smith' and convert dictionary to a list.

employee:
name: jane doe
gender: female
age: 24

The details for john:

KeyValue
namejohn smith
gendermale
age30
Answer
employee:
- name: jane doe
gender: female
age: 24

- name: john smith
gender: male
age: 30

7. Add the "payslip" details for Jane Doe.

employee:
name: jane doe
gender: female
age: 24
address:
city: 'orlando'
state: 'florida'
country: 'united states'

Her payslip details:

NumberMonthAmount
1april105,0000
2may120,000
3june98,000
4july110,000
Answer
employee:
name: jane doe
gender: female
age: 24
address:
city: 'orlando'
state: 'florida'
country: 'united states'
payslips:
- number: 1
amount: 105,000
month: 'april'

- number: 2
amount: 120,000
month: 'may'

- number: 3
amount: 98,000
month: 'june'

- number: 4
amount: 110,000
month: 'july'