226k views
3 votes
Given the variables name1 and name2, write a fragment of code that assigns the larger of their associated values to first.

User SEK
by
7.8k points

1 Answer

1 vote
We can compare strings like numbers,
if "a" > "b":
do something
Solutions will be

Python:
first = max(name1, name2)
second = min(name1, name2)

Or if we are not supposed to use max() and min(), we can achieve the same thing with a conditional,
Python:
if name1 > name2: ...
User Tien Nguyen
by
6.0k points