add pythons exercises
This commit is contained in:
parent
cb9a6de600
commit
f7ff97b3f3
@ -1,8 +1,8 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""Rozwiązanie zadania 102."""
|
||||
|
||||
def add_three_numbers(abc, bcd, cde):
|
||||
"""komentarz bo musi byc."""
|
||||
return abc+bcd+cde
|
||||
"""Task 102"""
|
||||
|
||||
def add_three_numbers(liczba1, liczba2, liczba3):
|
||||
|
||||
return liczba1 + liczba2 + liczba3
|
||||
|
||||
if __name__ == '__main__':
|
||||
print add_three_numbers(5, 7, -3)
|
||||
|
@ -1,13 +1,16 @@
|
||||
#!/usr/bin/python2
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""Rozwiązanie zadania 104."""
|
||||
|
||||
def fahrenheit(temperature):
|
||||
"""Convert Celsius to Fahrenheit"""
|
||||
if temperature < -273.15:
|
||||
return -459.67
|
||||
|
||||
return temperature * 9.0/5.0 + 32
|
||||
def sum_from_one_to_n(number):
|
||||
"""Placeholder"""
|
||||
if number < 1:
|
||||
return 0
|
||||
ret = 0
|
||||
for ile in range(1, number + 1):
|
||||
ret += ile * ile
|
||||
return ret
|
||||
|
||||
if __name__ == '__main__':
|
||||
print fahrenheit(10)
|
||||
print sum_from_one_to_n(2015)
|
||||
|
@ -1,17 +1,14 @@
|
||||
#!/usr/bin/python2
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""Rozwiązanie zadania 105."""
|
||||
|
||||
def is_almost_prime(number, limit):
|
||||
"""Checks if number can not be divided with limit offset"""
|
||||
if number < 0:
|
||||
return False
|
||||
def change_first(tuple_t, element_e):
|
||||
"""Docstring for Pylint points"""
|
||||
if not tuple_t:
|
||||
return ()
|
||||
|
||||
for i in range(2, limit + 1):
|
||||
if number%i == 0:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
if __name__ == '__main__':
|
||||
print is_almost_prime(5, 10)
|
||||
tuple_list = list(tuple_t)
|
||||
tuple_list[0] = element_e
|
||||
new_tuple = tuple(tuple_list)
|
||||
return new_tuple
|
||||
|
@ -1,11 +1,15 @@
|
||||
#!/usr/bin/python2
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""Rozwiązanie zadania 106."""
|
||||
|
||||
def penultimate(array, otherwise):
|
||||
"sprawdz liste"
|
||||
length = len(array)
|
||||
if length <= 1:
|
||||
return otherwise
|
||||
else:
|
||||
return array[length - 2]
|
||||
def freq_dic(seq):
|
||||
"""Placeholder"""
|
||||
dictionary = {}
|
||||
|
||||
for xxx in seq:
|
||||
if dictionary.has_key(xxx):
|
||||
dictionary[xxx] += 1
|
||||
else:
|
||||
dictionary[xxx] = 1
|
||||
return dictionary
|
||||
|
Loading…
Reference in New Issue
Block a user