diff --git a/syntactic-sugar-python/balance.py b/syntactic-sugar-python/balance.py index 3e84d19133..83fcaf468d 100644 --- a/syntactic-sugar-python/balance.py +++ b/syntactic-sugar-python/balance.py @@ -1,5 +1,5 @@ -debit = 300.00 -credit = 450.00 +debit = 300 +credit = 450 print( f"Debit: ${debit:.2f}, Credit: ${credit:.2f}, Balance: ${credit - debit:.2f}" @@ -10,3 +10,12 @@ debit, credit, credit - debit ) ) + +print( + "Debit: $" + + format(debit, ".2f") + + ", Credit: $" + + format(credit, ".2f") + + ", Balance: $" + + format(credit - debit, ".2f") +) diff --git a/syntactic-sugar-python/membership.py b/syntactic-sugar-python/membership.py index 49af2d913f..0178e01c83 100644 --- a/syntactic-sugar-python/membership.py +++ b/syntactic-sugar-python/membership.py @@ -3,3 +3,9 @@ def is_member(value, iterable): if current_value == value: return True return False + + +print(is_member(5, [1, 2, 3, 4, 5])) +print(not is_member(5, [1, 2, 3, 4, 5])) +print(is_member(100, [1, 2, 3, 4, 5])) +print(not is_member(100, [1, 2, 3, 4, 5])) diff --git a/syntactic-sugar-python/stack.py b/syntactic-sugar-python/stack.py index a551895da3..edb8180808 100644 --- a/syntactic-sugar-python/stack.py +++ b/syntactic-sugar-python/stack.py @@ -17,3 +17,14 @@ def __iter__(self): # def __iter__(self): # for item in self.items: # yield item + + +stack = Stack() +stack.push("one") +stack.push("two") +stack.push("three") + +for item in stack: + print(item) + +print(stack.pop()) diff --git a/syntactic-sugar-python/timing.py b/syntactic-sugar-python/timing.py index 484ea8a4c3..ed2ed08678 100644 --- a/syntactic-sugar-python/timing.py +++ b/syntactic-sugar-python/timing.py @@ -20,4 +20,4 @@ def delayed_mean(sample): return sum(sample) / len(sample) -delayed_mean([10, 2, 4, 7, 9, 3, 9, 8, 6, 7]) +print(delayed_mean([10, 2, 4, 7, 9, 3, 9, 8, 6, 7])) diff --git a/syntactic-sugar-python/user_input.py b/syntactic-sugar-python/user_input.py index da135869be..8b997ed357 100644 --- a/syntactic-sugar-python/user_input.py +++ b/syntactic-sugar-python/user_input.py @@ -1,3 +1,9 @@ +# With assignment operator +while (line := input("Type some text: ")) != "stop": + print(line) + + +# With assignment before loop line = input("Type some text: ") while line != "stop": @@ -5,6 +11,7 @@ line = input("Type some text: ") +# With condition inside loop while True: line = input("Type some text: ") if line == "stop":