Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # PRVI ZADATAK
- print('Zadatak 1:\n')
- vowels = ['a', 'e', 'i', 'o', 'u']
- example = 'lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
- def count_vowels(str):
- count = 0
- for char in str:
- if char in vowels:
- count += 1
- return count
- print(f"There are {count_vowels(example)} vowels in the given string.\n")
- # DRUGI ZADATAK
- print('Zadatak 2:\n')
- triplets = [
- [6, 2, 9],
- [31, 22, 12],
- [25, 10, 18],
- [34, 23, 19],
- [91, 50, 64],
- [10, 89, 35],
- [52, 31, 60],
- [14, 71, 28]
- ]
- def gimme(array):
- clone = array.copy()
- clone.sort()
- middle = clone[round((len(clone) - 1) / 2)]
- return array.index(middle)
- for array in triplets:
- print(
- f"The middle value of array {array} is located at index {gimme(array)}.")
- print()
- # TRECI ZADATAK
- print('Zadatak 3:\n')
- likers = [
- [],
- ['Mark'],
- ['Mark', 'Peter'],
- ['Mark', 'Peter', 'Jacob'],
- ['Mark', 'Peter', 'Jacob', 'Max'],
- ['Mark', 'Peter', 'Jacob', 'Max', 'Steve'],
- ['Mark', 'Peter', 'Jacob', 'Max', 'Steve', 'Angela'],
- ]
- def likes(array):
- length = len(array)
- if array and length > 0:
- if length is 1:
- return f'{array[0]} likes this'
- elif length is 2:
- return f'{array[0]} and {array[1]} like this'
- elif length is 3:
- return f'{array[0]}, {array[1]} and {array[2]} like this'
- else:
- return f'{array[0]}, {array[1]} and {length - 2} others like this'
- else:
- return 'No one likes this'
- for array in likers:
- print(likes(array))
Add Comment
Please, Sign In to add comment