diff --git a/python-6-46-level1-problems.py b/python-6-46-level1-problems.py index 3f9d567..bcfc8c9 100644 --- a/python-6-46-level1-problems.py +++ b/python-6-46-level1-problems.py @@ -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)) \ No newline at end of file diff --git a/python-6-47-level2-problems.py b/python-6-47-level2-problems.py new file mode 100644 index 0000000..5dcd895 --- /dev/null +++ b/python-6-47-level2-problems.py @@ -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])) \ No newline at end of file