Skip to content

Commit

Permalink
6-47
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgini committed Sep 4, 2018
1 parent 1fb9f1a commit 4c76eb9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
26 changes: 25 additions & 1 deletion python-6-46-level1-problems.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,29 @@ def old_macdonald(name):
rest_letters = name[4:]
return first_letter.upper() + inbtw_letter + fourth_letter.upper() + rest_letters

print (old_macdonald("pythonlearning"))
print(old_macdonald("macdonald"))
# same thing using capitalize
def new_macdonald(name):
first_half = name[:3]
second_half = name[3:]
return first_half.capitalize() + second_half.capitalize()

print(new_macdonald("macdonald"))

#reverse sentence
def master_yoda(text):
word_list = text.split()
r_word_list = word_list[::-1]
return " ".join(r_word_list) #join with a space instead of printing list

print(master_yoda("I am ready"))

#alost there - to return True if n within 10 of 100 or 200
# 90 - True
# 104 - True
# 150 - False
# 209 - True
def almost_there(n):
return (abs(100-n) <= 10) or (abs(200-n) <=10) #abs will return the absolute value of the number

print(almost_there(105))
8 changes: 8 additions & 0 deletions python-6-47-level2-problems.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# find in a list for nearby 3
def has_33(nums):
for i in range(0,len(nums)-1):
if nums[i] == 3 and nums[i+1] == 3: # or nums[i:i+1] == [3,3]
return True
return False

print (has_33([1,3,3]))

0 comments on commit 4c76eb9

Please sign in to comment.