Exercise: Conditionals

In this exercise, you'll define functions that consist entirely of compound conditionals (if/elif/else). Think carefully about the order of your conditions; sometimes order can have a big effect!


Lesser Num

📺 Need help getting started on this one? Watch me go through a similar problem in this video.

🧩 Or try a Parsons Puzzle version of the similar problem first.

def lesser_num(num1, num2): """ Returns whichever number is lowest of the two supplied numbers. >>> lesser_num(45, 10) 10 >>> lesser_num(-1, 30) -1 >>> lesser_num(20, 20) 20 """ # YOUR CODE HERE

Hello World

In this exercise, you'll use conditionals to translate a phrase into three different languages. Once you get the tests to pass, I encourage you to add another language you know!

🧩 For more guidance, try a Parsons Puzzle version of the problem first.

def hello_world(language_code): """ Returns the translation of "Hello, World" into the language specified by the language code (e.g. "es", "pt", "en"), defaulting to English if an unknown language code is specified. >>> hello_world("en") 'Hello, World' >>> hello_world("es") 'Hola, Mundo' >>> hello_world("pt") 'Olá, Mundo' """ # YOUR CODE HERE

Grade Assigner

🧩 For more guidance, try a Parsons Puzzle version of the problem first.

def assign_grade(score): """ Returns a letter grade for the numeric score based on the grade bins of: "A" (90-100), "B" (80-89), "C" (70-79), "D" (65-69), or "F" (0-64) >>> assign_grade(95) 'A' >>> assign_grade(90) 'A' >>> assign_grade(85) 'B' >>> assign_grade(80) 'B' >>> assign_grade(77) 'C' >>> assign_grade(70) 'C' >>> assign_grade(68) 'D' >>> assign_grade(65) 'D' >>> assign_grade(64) 'F' >>> assign_grade(0) 'F' """ return ''
➡️ Next up: User input