add pythons exercises

This commit is contained in:
Grzegorz Rogozik 2020-01-12 13:16:55 +01:00
parent cb9a6de600
commit f7ff97b3f3
4 changed files with 38 additions and 34 deletions

View File

@ -1,8 +1,8 @@
#!/usr/bin/python """Task 102"""
# -*- coding: utf-8 -*-
def add_three_numbers(liczba1, liczba2, liczba3):
"""Rozwiązanie zadania 102."""
return liczba1 + liczba2 + liczba3
def add_three_numbers(abc, bcd, cde):
"""komentarz bo musi byc.""" if __name__ == '__main__':
return abc+bcd+cde print add_three_numbers(5, 7, -3)

View File

@ -1,13 +1,16 @@
#!/usr/bin/python2
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""Rozwiązanie zadania 104.""" """Rozwiązanie zadania 104."""
def fahrenheit(temperature): def sum_from_one_to_n(number):
"""Convert Celsius to Fahrenheit""" """Placeholder"""
if temperature < -273.15: if number < 1:
return -459.67 return 0
ret = 0
return temperature * 9.0/5.0 + 32 for ile in range(1, number + 1):
ret += ile * ile
return ret
if __name__ == '__main__': if __name__ == '__main__':
print fahrenheit(10) print sum_from_one_to_n(2015)

View File

@ -1,17 +1,14 @@
#!/usr/bin/python2
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""Rozwiązanie zadania 105.""" """Rozwiązanie zadania 105."""
def is_almost_prime(number, limit): def change_first(tuple_t, element_e):
"""Checks if number can not be divided with limit offset""" """Docstring for Pylint points"""
if number < 0: if not tuple_t:
return False return ()
for i in range(2, limit + 1): tuple_list = list(tuple_t)
if number%i == 0: tuple_list[0] = element_e
return False new_tuple = tuple(tuple_list)
return new_tuple
return True
if __name__ == '__main__':
print is_almost_prime(5, 10)

View File

@ -1,11 +1,15 @@
#!/usr/bin/python2
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""Rozwiązanie zadania 106.""" """Rozwiązanie zadania 106."""
def penultimate(array, otherwise): def freq_dic(seq):
"sprawdz liste" """Placeholder"""
length = len(array) dictionary = {}
if length <= 1:
return otherwise for xxx in seq:
else: if dictionary.has_key(xxx):
return array[length - 2] dictionary[xxx] += 1
else:
dictionary[xxx] = 1
return dictionary