Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coolest palindrome sample solution #7

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions week6/3-Forecast/forecast.py
Original file line number Diff line number Diff line change
@@ -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"]))
29 changes: 29 additions & 0 deletions week6/3-Forecast/solutions/forecast.py
Original file line number Diff line number Diff line change
@@ -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"]))
8 changes: 8 additions & 0 deletions week7/1-Taken-Name/solutions/surname.py
Original file line number Diff line number Diff line change
@@ -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"))
19 changes: 19 additions & 0 deletions week7/2-Coolest-Palindrome/solutions/is_string_palindrom.py
Original file line number Diff line number Diff line change
@@ -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! "))