From 5021214ddbbb72e9a6314f12f98a482a8e863b49 Mon Sep 17 00:00:00 2001 From: Mihail Petrov Date: Thu, 12 Nov 2015 14:13:21 +0200 Subject: [PATCH 1/4] sample solution for week6/forecast --- week6/3-Forecast/forecast.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 week6/3-Forecast/forecast.py diff --git a/week6/3-Forecast/forecast.py b/week6/3-Forecast/forecast.py new file mode 100644 index 0000000..dd9587e --- /dev/null +++ b/week6/3-Forecast/forecast.py @@ -0,0 +1,29 @@ +def forecast(days): + d = {"rain": 0, 'sunshine': 0, 'snow': 0} + tomorrow = '' + li = [] + for item in days: + if item == 'rain': + d['rain'] += 1 + if item == 'sunshine': + d['sunshine'] += 1 + if item == 'snow': + d['snow'] += 1 + for values in d.values(): + li.append(values) + li.sort() + print(li) + if li[2] > li[1]: + for key, value in d.items(): + if value == li[2]: + tomorrow = key + if li[2] == li[1]: + if li[2] == li[0]: + tomorrow = days[len(days)-1] + else: + for key, value in d.items(): + if value == li[0]: + tomorrow = key + return tomorrow + +print(forecast(["rain", "rain", "sunshine", "sunshine"])) \ No newline at end of file From 09742bc18b26abcb1fd2474d545d10224762f291 Mon Sep 17 00:00:00 2001 From: Mihail Petrov Date: Thu, 12 Nov 2015 14:22:58 +0200 Subject: [PATCH 2/4] sample solution forecast problem --- week6/3-Forecast/solutions/forecast.py | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 week6/3-Forecast/solutions/forecast.py diff --git a/week6/3-Forecast/solutions/forecast.py b/week6/3-Forecast/solutions/forecast.py new file mode 100644 index 0000000..dd9587e --- /dev/null +++ b/week6/3-Forecast/solutions/forecast.py @@ -0,0 +1,29 @@ +def forecast(days): + d = {"rain": 0, 'sunshine': 0, 'snow': 0} + tomorrow = '' + li = [] + for item in days: + if item == 'rain': + d['rain'] += 1 + if item == 'sunshine': + d['sunshine'] += 1 + if item == 'snow': + d['snow'] += 1 + for values in d.values(): + li.append(values) + li.sort() + print(li) + if li[2] > li[1]: + for key, value in d.items(): + if value == li[2]: + tomorrow = key + if li[2] == li[1]: + if li[2] == li[0]: + tomorrow = days[len(days)-1] + else: + for key, value in d.items(): + if value == li[0]: + tomorrow = key + return tomorrow + +print(forecast(["rain", "rain", "sunshine", "sunshine"])) \ No newline at end of file From b2624d8f2f95e9a3e14ea1b03c0d7a5d5009f525 Mon Sep 17 00:00:00 2001 From: Mihail Petrov Date: Thu, 12 Nov 2015 14:38:53 +0200 Subject: [PATCH 3/4] sample solution name_taken problem --- week7/1-Taken-Name/solutions/surname.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 week7/1-Taken-Name/solutions/surname.py diff --git a/week7/1-Taken-Name/solutions/surname.py b/week7/1-Taken-Name/solutions/surname.py new file mode 100644 index 0000000..c510ac5 --- /dev/null +++ b/week7/1-Taken-Name/solutions/surname.py @@ -0,0 +1,8 @@ +def taken_name(surname_husband, surname_wife): + if surname_husband in surname_wife: + return True + else: + return False + +print(taken_name("Petrov", "Ivanova-Petrova")) +print(taken_name("Andonov", "Karapitonova")) \ No newline at end of file From 3094e0139360b961fa06729d8c960ff46e800fe6 Mon Sep 17 00:00:00 2001 From: Mihail Petrov Date: Thu, 12 Nov 2015 14:44:31 +0200 Subject: [PATCH 4/4] Coolest palindrome sample solution --- .../solutions/is_string_palindrom.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 week7/2-Coolest-Palindrome/solutions/is_string_palindrom.py diff --git a/week7/2-Coolest-Palindrome/solutions/is_string_palindrom.py b/week7/2-Coolest-Palindrome/solutions/is_string_palindrom.py new file mode 100644 index 0000000..337d872 --- /dev/null +++ b/week7/2-Coolest-Palindrome/solutions/is_string_palindrom.py @@ -0,0 +1,19 @@ +def is_string_palindrom(string): + new_string = '' + marks = [',', '.', '?', '!', ' '] + + for c in string: + if c not in marks: + new_string += c + + new_string = new_string.lower() + + for i in range(0, len(new_string)//2): + if new_string[i] == new_string[len(new_string)-1-i]: + continue + else: + return False + return True +print(is_string_palindrom("A Toyota!")) +print(is_string_palindrom("bozaa")) +print(is_string_palindrom(" kapak! ")) \ No newline at end of file