Exercise: String Comparison

Let's create conditions based on the lengths of strings.

Problem Statement

You are given three strings, str1, str2.

If str1 is longer in length, str2 will be appended to it. If str2 is longer, str1 will be appended to it.

In case both of them have the same length, str2 will be appended to str1.

Sample Input

str1 = "Venus"
str2 = "Neptune"

Sample Output

"NeptuneVenus"

Coding Challenge

Think carefully about how this problem can be solved based on the conditionals we have studied in this section. It may be a good idea to write down the logic on a piece of paper first.

Note: You do not have to store the appended result anywhere. Just write the expression used for appending one string to the other.

If you feel stuck, you can always refer to the solution review in the next lesson.

Good luck!

Get hands-on with 1200+ tech skills courses.