Compare commits

...

2 Commits

3 changed files with 28 additions and 1 deletions

View File

@ -17,4 +17,5 @@ Repository for CDS-2020 Programming and Promt Engineering II
# Codewars # Codewars
|Title|Source (src/codewars/)|Test (test/codewars/)|URL| |Title|Source (src/codewars/)|Test (test/codewars/)|URL|
|-|-|-|-| |-|-|-|-|
|Find the force of gravity between two objects|kata_force_of_gravity.py|test_force_of_gravity.py|[URL](https://www.codewars.com/kata/5b609ebc8f47bd595e000627/)| |Find the force of gravity between two objects|kata_force_of_gravity.py|test_force_of_gravity.py|[5b609ebc8f47bd595e000627](https://www.codewars.com/kata/5b609ebc8f47bd595e000627/)|
|The Lamp: Revisited|kata_the_lamp.py|test_the_lamp.py|[570e6e32de4dc8a8340016dd](https://www.codewars.com/kata/570e6e32de4dc8a8340016dd)|

View File

@ -0,0 +1,13 @@
class Lamp:
def __init__(self, color: str):
self.color = color
self.on = False
def toggle_switch(self):
self.on = not self.on
def state(self):
if self.on:
return "The lamp is on."
return "The lamp is off."

View File

@ -0,0 +1,13 @@
from src.codewars.kata_the_lamp import Lamp
def test_lamp():
my_lamp = Lamp("Blue")
assert my_lamp.color == "Blue"
assert not my_lamp.on
assert my_lamp.state() == "The lamp is off."
my_lamp.toggle_switch()
assert my_lamp.state() == "The lamp is on."
my_lamp.toggle_switch()
assert my_lamp.state() == "The lamp is off."