37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
from typing import List
|
|
|
|
def substring(string: str, start: int, letters: int =None) -> str:
|
|
"""
|
|
creates a substring from a given string
|
|
:param string: the original string
|
|
:param start: the start index
|
|
:param letters: the amount of letters in the substring
|
|
:return: the substring
|
|
"""
|
|
length = len(string)
|
|
if start > length:
|
|
raise ValueError ("Start index must be smaller than stringlenght")
|
|
if letters is None:
|
|
letters = length - start
|
|
if letters + start > length:
|
|
raise ValueError ("Sum of start and numbers of letters is grater that stringlength")
|
|
if start <0:
|
|
raise ValueError (" Start must be positive")
|
|
return string[start: start+ letters]
|
|
|
|
if __name__ == "__main__":
|
|
original = "GEEKSFORGEEKS"
|
|
print(substring(original, 0, 5)) # Output: GEEKS
|
|
print(substring(original, 5)) # Output: FORGEEKS
|
|
|
|
|
|
def product (numbers:List)-> int:
|
|
temp = 1
|
|
result = 1
|
|
for i in numbers:
|
|
result *= i
|
|
i += 1
|
|
return result
|
|
|
|
if __name__ == "__main__":
|
|
print(product([1,2,3])) |