Python Operator Exercises Let’s check out some exercises that will help understand Python Operators better. Exercise 18-a: Assignment Operator = Let's start with the most basic . Assign a list of colors to the variable: ["yellow", "white", "blue"] #Type your answer below lst= print(lst) ==== from unittest.gui import TestCaseGui class myTests(TestCaseGui): def testOne(self): self.assertEqual(lst,["yellow", "white", "blue"],"lst checks") myTests().main() Hint 1 Assignment operator is:=Assignee (variable) goes to the left of the = sign and value(s) being assigned goes to the right of the = sign. Solution lst = ["yellow", "white", "blue"] Exercise 18-b: Division Operator / Assign division of a to b to the variable. a=10 b=3 #Type your answer below result= print(result) ==== from unittest.gui import TestCaseGui class myTests(TestCaseGui): def testOne(self): self.assertEqual(result,10/3,"result checks") myTests().main() Hint 1 Division operator which is an arithmetic operator is: / Solution result=a/b Exercise 18-c: Addition using += Add 100 to the variable using +=. vertical_speed=750 #Type your answer below print(vertical_speed) ==== from unittest.gui import TestCaseGui class myTests(TestCaseGui): def testOne(self): self.assertEqual(vertical_speed,850,"value checks") myTests().main() Hint 1 You can use arithmetic assignment operator += Solution vertical_speed+=100 Exercise 18-d: Modulus % Using modulus operator assign the remainder of 1000/400 to the variable. #Type your code here remainder= print(remainder) ==== from unittest.gui import TestCaseGui class myTests(TestCaseGui): def testOne(self): self.assertEqual(remainder,200,"value checks") myTests().main() Hint 1 You can use the modulus operator to get a division remainder: % Solution remainder=1000%400 Exercise 18-e: Power Operator ** Using power operator **, assign the square of 11111 to the variable. #Type your code here p_result= print(p_result) ==== from unittest.gui import TestCaseGui class myTests(TestCaseGui): def testOne(self): self.assertEqual(p_result,11111**2,"square checks") myTests().main() Hint 1 You can use ** power operator as below:**2 Solution p_result=11111**2 Exercise 18-f: Comparison Operator == Write a conditional statement (if else) which checks the first element in a list (index zero) and assign answer_1 to "Yes" if the first element is equal to "strawberry" else it should assign answer_1 to "No". lst=["Mango", "Kiwi", "Melon", "Cherry"] answer_1="" #Type your code here print(answer_1) ==== from unittest.gui import TestCaseGui class myTests(TestCaseGui): def testOne(self): self.assertEqual(answer_1,"No","answer_1 checks") myTests().main() Hint 1 In conditional statements comparison operator == is used to check if 2 values are equal.== Hint 2 lst[0] can be used to access the first element of the list. Hint 3 if else structure can be used to create a conditional statement.Please refer to this lesson if you need to refresh your knowledge of conditional statements (if, elif, else): Conditional Statements Solution if lst[0]=="strawberry": answer_1="Yes" else: answer_1="No"