Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- This is a list of functions that should be completed.
- """
- from typing import Any
- from typing import List
- class OurAwesomeException(Exception):
- pass
- def is_two_object_has_same_value(first: Any, second: Any) -> bool:
- """
- If @first and @second has same value should return True
- In another case should return False
- """
- return first == second
- def is_two_objects_has_same_type(first: Any, second: Any) -> bool:
- """
- If @first and @second has same type should return True
- In another case should return False
- """
- return type(first) == type(second)
- def is_two_objects_is_the_same_objects(first: Any, second: Any) -> bool:
- """
- If @first and @second has same type should return True
- In another case should return False
- """
- return id(first) == id(second)
- def multiple_ints(first_value: int, second_value: int) -> int:
- """
- Should calculate product of all args.
- if first_value or second_value is not int should raise ValueError
- Raises:
- ValueError
- Params:
- first_value: value for multiply
- second_value
- Returns:
- Product of elements
- """
- # if int(first_value) and int(second_value):
- # return first_value * second_value
- # else:
- # raise ValueError
- try:
- val1=int(first_value)
- val2=int(second_value)
- return first_value * second_value
- except TypeError:
- raise ValueError
- def multiple_ints_with_conversion(first_value: Any, second_value: Any) -> int:
- """
- If possible to convert arguments to int value - convert and multiply them.
- If it is impossible raise OurAwesomeException
- Args:
- first_value: number for multiply
- second_value: number for multiply
- Raises:
- OurAwesomeException
- Returns: multiple of two numbers.
- Examples:
- multiple_ints_with_conversion(6, 6)
- >>> 36
- multiple_ints_with_conversion(2, 2.0)
- >>> 4
- multiple_ints_with_conversion("12", 1)
- >>> 12
- try:
- multiple_ints_with_conversion("Hello", 2)
- except ValueError:
- print("Not valid input data")
- >>> "Not valid input data"
- """
- first_value = int(first_value)
- second_value = int(second_value)
- try:
- return first_value * second_value
- except ValueError:
- raise OurAwesomeException
- print("Not valid inpup data")
- def is_word_in_text(word: str, text: str) -> bool:
- """
- If text contain word return True
- In another case return False.
- Args:
- word: Searchable substring
- text: Text for searching
- Examples:
- is_word_in_text("Hello", "Hello word")
- >>> True
- is_word_in_text("Glad", "Nice to meet you ")
- >>> False
- """
- if word in text:
- return True
- else:
- return False
- def some_loop_exercise() -> list:
- """
- Use loop to create list that contain int values from 0 to 12 except 6 and 7
- """
- our_list = list(range(0,13))
- for i in our_list:
- if i == 6:
- our_list.remove(i)
- for j in our_list:
- if j == 7:
- our_list.remove(j)
- return our_list
- #shitcode
- def remove_from_list_all_negative_numbers(data: List[int]) -> list:
- """
- Use loops to solve this task.
- You could use data.remove(negative_number) to solve this issue.
- Also you could create new list with only positive numbers.
- Examples:
- remove_from_list_all_negative_numbers([1, 5, -7, 8, -1])
- >>> [1, 5, 8]
- """
- right = data[:]
- for i in data:
- if i < 0:
- right.remove(i)
- return right
- def alphabet() -> dict:
- """
- Create dict which keys is alphabetic characters. And values their number in alphabet
- Notes You could see an implementaion of this one in test, but create another one
- Examples:
- alphabet()
- >>> {"a": 1, "b": 2 ...}
- """
- letters = ['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']
- numbers = list(range(1, len(letters) + 1))
- return dict(zip(numbers, letters))
- def simple_sort(data: List[int]) -> List[list]:
- """
- Sort list of ints without using built-in methods.
- Examples:
- simple_sort([2, 9, 6, 7, 3, 2, 1])
- >>> [1, 2, 2, 3, 6, 7, 9]
- Returns:
- """
- new_list = []
- while data:
- min = data[0]
- for x in data:
- if x < min:
- min = x
- new_list.append(min)
- data.remove(min)
- return new_list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement