Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def is_number_balanced(num):
- num = (list(str(num)))
- num = [int(i) for i in num]
- half = len(num) // 2
- if len(num) % 2:
- lhs = num[:half]
- rhs = num[half + 1:]
- else:
- lhs = num[:half]
- rhs = num[half:]
- return sum(lhs) == sum(rhs)
- print(is_number_balanced(9))
- print(is_number_balanced(4518))
- print(is_number_balanced(28471))
- print(is_number_balanced(1238033))
- print("\n\n")
- def increasing_or_decreasing(seq):
- result = []
- for x in range(0, len(seq) - 1):
- if(seq[x + 1] > seq[x]):
- result.append(1)
- elif (seq[x + 1] == seq[x]):
- result.append(0)
- else:
- result.append(-1)
- if sum(result) == len(result):
- return "Up!"
- elif sum(result) == -len(result):
- return "Down!"
- else:
- return False
- print(increasing_or_decreasing([1, 2, 3, 4, 5]))
- print(increasing_or_decreasing([5, 6, -10]))
- print(increasing_or_decreasing([1, 1, 1, 1]))
- print(increasing_or_decreasing([9, 8, 7, 6]))
- print("\n\n")
- # def get_largest_palindrome(num):
- def sum_of_numbers(input_string):
- nums = [0]
- temp = ""
- prev = False
- for i in range(len(input_string)):
- if input_string[i].isdigit():
- if not i == len(input_string) - 1:
- temp += input_string[i]
- prev = True
- else:
- temp += input_string[i]
- nums.append(temp)
- else:
- if prev:
- nums.append(temp)
- prev = False
- temp = ""
- nums = [int(i) for i in nums]
- return sum(nums)
- print(sum_of_numbers("ab125cd3"))
- print(sum_of_numbers("ab12"))
- print(sum_of_numbers("ab"))
- print(sum_of_numbers("1101"))
- print(sum_of_numbers("1111O"))
- print(sum_of_numbers("1abc33xyz22"))
- print(sum_of_numbers("0hfabnek"))
- print("\n\n")
- def birthday_ranges(birthdays, ranges):
- people = []
- counter = 0
- for period in ranges:
- for day in birthdays:
- if period[0] <= day and period[1] >= day:
- counter += 1
- people.append(counter)
- counter = 0
- return people
- print(birthday_ranges([1, 2, 3, 4, 5],
- [(1, 2), (1, 3), (1, 4), (1, 5), (4, 6)]))
- print(birthday_ranges([5, 10, 6, 7, 3, 4, 5, 11, 21, 300, 15],
- [(4, 9), (6, 7), (200, 225), (300, 365)]))
- print("\n\n")
- def group(elem):
- from itertools import groupby
- return [list(grp) for k, grp in groupby(elem)]
- def capitalise(a):
- return a
- def numbers_to_message(pressed_sequence):
- keypad = [[" "], [""], ["a", "b", "c"], ["d", "e", "f"],
- ["g", "h", "i"], ["j", "k", "l"], ["m", "n", "o"],
- ["p", "q", "r", "s"], ["t", "u", "v"], ["w", "x", "y", "z"]]
- pressed_sequence = group(pressed_sequence)
- # print(keypad)
- for item in pressed_sequence:
- print(len(item))
- if item == 1:
- continue
- else:
- continue
- print(numbers_to_message([2, -1, 2, 2, -1, 2, 2, 2]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement