Compare commits
2 Commits
e224fa51ec
...
515df4d452
| Author | SHA1 | Date | |
|---|---|---|---|
| 515df4d452 | |||
| bc6f7e27aa |
@ -17,4 +17,5 @@ Repository for CDS-2020 Programming and Promt Engineering II
|
||||
# Codewars
|
||||
|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)|
|
||||
|
||||
13
src/codewars/kata_the_lamp.py
Normal file
13
src/codewars/kata_the_lamp.py
Normal 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."
|
||||
13
tests/codewars/test_the_lamp.py
Normal file
13
tests/codewars/test_the_lamp.py
Normal 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."
|
||||
Loading…
x
Reference in New Issue
Block a user