Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Challenge: Car Brands | Python if-elif-else Statement
Conditional Statements in Python
course content

Course Content

Conditional Statements in Python

Conditional Statements in Python

1. Python if Statement
2. Python if-else Statement
3. Python if-elif-else Statement
4. Python Ternary Operator

bookChallenge: Car Brands

Task
test

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']

  1. Create an empty list using square brackets, and name it new_list;
  2. Iterate through all the elements of the original list using a for loop;
  3. Next, check if the element from the list is equal to bmw, kia, and so on, using if-elif-else statements;
  4. For brand names that need to be in uppercase, use the upper() method;
  5. For brand names that need to be capitalized, use the title() method;
  6. Add the corrected brand names to the new_list using the append() method.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 3. Chapter 2
toggle bottom row

bookChallenge: Car Brands

Task
test

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']

  1. Create an empty list using square brackets, and name it new_list;
  2. Iterate through all the elements of the original list using a for loop;
  3. Next, check if the element from the list is equal to bmw, kia, and so on, using if-elif-else statements;
  4. For brand names that need to be in uppercase, use the upper() method;
  5. For brand names that need to be capitalized, use the title() method;
  6. Add the corrected brand names to the new_list using the append() method.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 3. Chapter 2
toggle bottom row

bookChallenge: Car Brands

Task
test

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']

  1. Create an empty list using square brackets, and name it new_list;
  2. Iterate through all the elements of the original list using a for loop;
  3. Next, check if the element from the list is equal to bmw, kia, and so on, using if-elif-else statements;
  4. For brand names that need to be in uppercase, use the upper() method;
  5. For brand names that need to be capitalized, use the title() method;
  6. Add the corrected brand names to the new_list using the append() method.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Task
test

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']

  1. Create an empty list using square brackets, and name it new_list;
  2. Iterate through all the elements of the original list using a for loop;
  3. Next, check if the element from the list is equal to bmw, kia, and so on, using if-elif-else statements;
  4. For brand names that need to be in uppercase, use the upper() method;
  5. For brand names that need to be capitalized, use the title() method;
  6. Add the corrected brand names to the new_list using the append() method.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Section 3. Chapter 2
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
We're sorry to hear that something went wrong. What happened?
some-alt