Course Content
Conditional Statements in Python
Conditional Statements in Python
Challenge: Car Brands
Swipe to show code editor
You have a list of car brands, which currently looks like this:
['mazda', 'lexus', 'bmw', 'tesla', 'kia']
As you can see, some brand names are not correctly formatted. Specifically, bmw
and kia
should be in uppercase, while the other brands should be capitalized.
To rectify this, you need to adjust all the names in the list cars
to the correct format and store them in a new new_list
. As a result, you should end up with a new new_list
that appears like this:
['Mazda', 'Lexus', 'BMW', 'Tesla', 'KIA']
- Create an empty list using square brackets, and name it
new_list
; - Iterate through all the elements of the original list using a
for
loop; - Next, check if the element from the list is equal to
bmw
,kia
, and so on, usingif-elif-else
statements; - For brand names that need to be in uppercase, use the
upper()
method; - For brand names that need to be capitalized, use the
title()
method; - Add the corrected brand names to the
new_list
using theappend()
method.
Thanks for your feedback!
Challenge: Car Brands
Swipe to show code editor
You have a list of car brands, which currently looks like this:
['mazda', 'lexus', 'bmw', 'tesla', 'kia']
As you can see, some brand names are not correctly formatted. Specifically, bmw
and kia
should be in uppercase, while the other brands should be capitalized.
To rectify this, you need to adjust all the names in the list cars
to the correct format and store them in a new new_list
. As a result, you should end up with a new new_list
that appears like this:
['Mazda', 'Lexus', 'BMW', 'Tesla', 'KIA']
- Create an empty list using square brackets, and name it
new_list
; - Iterate through all the elements of the original list using a
for
loop; - Next, check if the element from the list is equal to
bmw
,kia
, and so on, usingif-elif-else
statements; - For brand names that need to be in uppercase, use the
upper()
method; - For brand names that need to be capitalized, use the
title()
method; - Add the corrected brand names to the
new_list
using theappend()
method.
Thanks for your feedback!
Challenge: Car Brands
Swipe to show code editor
You have a list of car brands, which currently looks like this:
['mazda', 'lexus', 'bmw', 'tesla', 'kia']
As you can see, some brand names are not correctly formatted. Specifically, bmw
and kia
should be in uppercase, while the other brands should be capitalized.
To rectify this, you need to adjust all the names in the list cars
to the correct format and store them in a new new_list
. As a result, you should end up with a new new_list
that appears like this:
['Mazda', 'Lexus', 'BMW', 'Tesla', 'KIA']
- Create an empty list using square brackets, and name it
new_list
; - Iterate through all the elements of the original list using a
for
loop; - Next, check if the element from the list is equal to
bmw
,kia
, and so on, usingif-elif-else
statements; - For brand names that need to be in uppercase, use the
upper()
method; - For brand names that need to be capitalized, use the
title()
method; - Add the corrected brand names to the
new_list
using theappend()
method.
Thanks for your feedback!
Swipe to show code editor
You have a list of car brands, which currently looks like this:
['mazda', 'lexus', 'bmw', 'tesla', 'kia']
As you can see, some brand names are not correctly formatted. Specifically, bmw
and kia
should be in uppercase, while the other brands should be capitalized.
To rectify this, you need to adjust all the names in the list cars
to the correct format and store them in a new new_list
. As a result, you should end up with a new new_list
that appears like this:
['Mazda', 'Lexus', 'BMW', 'Tesla', 'KIA']
- Create an empty list using square brackets, and name it
new_list
; - Iterate through all the elements of the original list using a
for
loop; - Next, check if the element from the list is equal to
bmw
,kia
, and so on, usingif-elif-else
statements; - For brand names that need to be in uppercase, use the
upper()
method; - For brand names that need to be capitalized, use the
title()
method; - Add the corrected brand names to the
new_list
using theappend()
method.