From 4443746c71a894f45dee6316df4695fee839286a Mon Sep 17 00:00:00 2001 From: Mike Lane Date: Tue, 9 Oct 2018 08:37:44 -0700 Subject: [PATCH 1/3] 8 Update filename --- beginner/sum-earnings-mikelane.py | 60 +++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 beginner/sum-earnings-mikelane.py diff --git a/beginner/sum-earnings-mikelane.py b/beginner/sum-earnings-mikelane.py new file mode 100644 index 0000000..b7ac443 --- /dev/null +++ b/beginner/sum-earnings-mikelane.py @@ -0,0 +1,60 @@ +import functools + + +def sum_earnings(s: str) -> int: + """ + Challenge + - Write a function that accepts a comma-separated string input of + earning/spending activity and returns the sum of earnings as a + single int value. + + - If at any point the spending (negative) value is greater than the + sum of earned (positive) values before it then the streak ends and + the count should start over + + We have a list in string type separated by commas that represented + buy or sell activity. Positive value for selling and negative value + for buying activity. For example, in the following string, this + user sold something for $7 on the 2nd day, and something for $2 on + the 4th day, and then bought something for $12 on the 5th day, and + so on. + + >>> sum_earnings('0,7,0,2,-12,3,0,2') + 5 + + This user's highest earnings streak is $5, which started on the 6th + day and ended on the 8th day. The streak does not start before the + 6th day because the user spent $12 on the 5th and broke earlier + streak on $9. + + >>> sum_earnings('1,3,-2,1,2') + 5 + + Notes + If the user did not do anything (i.e. 0,0,0,0,0) or only bought + things without selling anything (i.e. -4,-3,-7,-1), then it should + output with 0. + + >>> sum_earnings('0,0,0,0,0') + 0 + >>> sum_earnings('-4,-3,-7,-1') + 0 + + Your program should be able to handle a comma-separated string + consisting of any number of values. Your program should also be + able to handle invalid input. If an invalid input is given, it + should output 0. + + some examples of invalid input: + + >>> sum_earnings('qwerty') + 0 + >>> sum_earnings(',,3,,4') + 0 + >>> sum_earnings('1,2,v,b,3') + 0 + """ + try: + return functools.reduce(lambda x, y: max(0, x + y), map(int, s.split(','))) + except ValueError: + return 0 From 36826f95d2f1aed3fb67ba99ecb4da422c56ad32 Mon Sep 17 00:00:00 2001 From: Willman <44055487+Unimpressions@users.noreply.github.com> Date: Fri, 12 Oct 2018 02:56:10 +1000 Subject: [PATCH 2/3] initial solution to Profile Lookup --- beginner/Profile-Lookup_Unimpressions.py | 41 ++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 beginner/Profile-Lookup_Unimpressions.py diff --git a/beginner/Profile-Lookup_Unimpressions.py b/beginner/Profile-Lookup_Unimpressions.py new file mode 100644 index 0000000..1cdacb0 --- /dev/null +++ b/beginner/Profile-Lookup_Unimpressions.py @@ -0,0 +1,41 @@ +contacts = [ + { + "firstName": "Akira", + "lastName": "Laine", + "number": "0543236543", + "likes": ["Pizza", "Coding", "Brownie Points"] + }, + { + "firstName": "Harry", + "lastName": "Potter", + "number": "0994372684", + "likes": ["Hogwarts", "Magic", "Hagrid"] + }, + { + "firstName": "Sherlock", + "lastName": "Holmes", + "number": "0487345643", + "likes": ["Intriguing Cases", "Violin"] + }, + { + "firstName": "Kristian", + "lastName": "Vos", + "number": "unknown", + "likes": ["JavaScript", "Gaming", "Foxes"] + } +]; + + +def look_up_profile(name, field): + for lookup in contacts: + lookupname = lookup.get('firstName') + if lookupname.casefold() == name.casefold(): + lookupfield = lookup.get(field) + if lookupfield == lookup[field]: + return lookupfield + else: + return "No Such property." + return "No such contact." + +#Change these values to test your function +print(look_up_profile("Akira", "number")) From e9ac4c5986590be60c32aa18382dc35f066b1920 Mon Sep 17 00:00:00 2001 From: Szymon Bielenica <34723927+sbielenica@users.noreply.github.com> Date: Thu, 11 Oct 2018 20:48:32 +0200 Subject: [PATCH 3/3] Add files via upload --- beginner/sum-earnings-sbielenica.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 beginner/sum-earnings-sbielenica.py diff --git a/beginner/sum-earnings-sbielenica.py b/beginner/sum-earnings-sbielenica.py new file mode 100644 index 0000000..a8d5adb --- /dev/null +++ b/beginner/sum-earnings-sbielenica.py @@ -0,0 +1,18 @@ + +def sum_earning(input): + + streak = 0 + total_sum = 0 + + for num in input: + if num >= 0: + streak += 1 + total_sum += num + elif num < 0: + streak = 0 + total_sum = 0 + + return total_sum + + +print(sum_earning([0,7,0,2,-12,3,0,2]))