diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-12-14 13:41:58 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-14 13:41:58 +0000 |
| commit | 681bb63998c1e90ac5003e4e40cff1e7a483c09d (patch) | |
| tree | 76c4f582396e8e55b520ea2a8f12f91671885d11 /challenge-027/paulo-custodio/python/ch-2.py | |
| parent | 4275350afa4af784128e003cbec62bd23404f80b (diff) | |
| parent | 8c1fdda84743187534ae4615a0dfcb41283293e4 (diff) | |
| download | perlweeklychallenge-club-681bb63998c1e90ac5003e4e40cff1e7a483c09d.tar.gz perlweeklychallenge-club-681bb63998c1e90ac5003e4e40cff1e7a483c09d.tar.bz2 perlweeklychallenge-club-681bb63998c1e90ac5003e4e40cff1e7a483c09d.zip | |
Merge pull request #5370 from pauloscustodio/devel
Devel
Diffstat (limited to 'challenge-027/paulo-custodio/python/ch-2.py')
| -rw-r--r-- | challenge-027/paulo-custodio/python/ch-2.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-027/paulo-custodio/python/ch-2.py b/challenge-027/paulo-custodio/python/ch-2.py new file mode 100644 index 0000000000..99fd57554b --- /dev/null +++ b/challenge-027/paulo-custodio/python/ch-2.py @@ -0,0 +1,26 @@ +#!/usr/bin/python3 + +# Challenge 027 +# +# Task #2 +# Write a script that allows you to capture/display historical data. It could +# be an object or a scalar. For example +# +# my $x = 10; $x = 20; $x -= 5; +# +# After the above operations, it should list $x historical value in order. + +class LoggingScalar: + def __init__(self, value): + self.values = [value] + def set(self, value): + self.values.append(value) + def get(self): + return self.values[-1] + def show_hist(self): + print(" ".join([str(x) for x in self.values])) + +x = LoggingScalar(10) +x.set(20) +x.set(x.get()-5) +x.show_hist() |
