Skip to content

Commit

Permalink
Add more output
Browse files Browse the repository at this point in the history
  • Loading branch information
gahjelle committed Sep 18, 2024
1 parent c5edc5c commit 61d4786
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
13 changes: 11 additions & 2 deletions syntactic-sugar-python/balance.py
Original file line number Diff line number Diff line change
@@ -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}"
Expand All @@ -10,3 +10,12 @@
debit, credit, credit - debit
)
)

print(
"Debit: $"
+ format(debit, ".2f")
+ ", Credit: $"
+ format(credit, ".2f")
+ ", Balance: $"
+ format(credit - debit, ".2f")
)
6 changes: 6 additions & 0 deletions syntactic-sugar-python/membership.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
11 changes: 11 additions & 0 deletions syntactic-sugar-python/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
2 changes: 1 addition & 1 deletion syntactic-sugar-python/timing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
7 changes: 7 additions & 0 deletions syntactic-sugar-python/user_input.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# With assignment operator
while (line := input("Type some text: ")) != "stop":
print(line)


# With assignment before loop
line = input("Type some text: ")

while line != "stop":
print(line)
line = input("Type some text: ")


# With condition inside loop
while True:
line = input("Type some text: ")
if line == "stop":
Expand Down

0 comments on commit 61d4786

Please sign in to comment.