add pythons exercises
This commit is contained in:
parent
bcb001350a
commit
cb9a6de600
8
intro/Task102.py
Normal file
8
intro/Task102.py
Normal file
@ -0,0 +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
|
11
intro/Task103.py
Normal file
11
intro/Task103.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""Rozwiązanie zadania 103."""
|
||||||
|
|
||||||
|
def probability(abc):
|
||||||
|
"""Komentarz"""
|
||||||
|
if abc >= 0.0 and abc <= 1.0:
|
||||||
|
return abc
|
||||||
|
else:
|
||||||
|
return 0
|
13
intro/Task104.py
Normal file
13
intro/Task104.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# -*- 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
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
print fahrenheit(10)
|
17
intro/Task105.py
Normal file
17
intro/Task105.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# -*- 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
|
||||||
|
|
||||||
|
for i in range(2, limit + 1):
|
||||||
|
if number%i == 0:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
print is_almost_prime(5, 10)
|
11
intro/Task106.py
Normal file
11
intro/Task106.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# -*- 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]
|
15
intro/Task107.py
Normal file
15
intro/Task107.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""Rozwiązanie zadania 107."""
|
||||||
|
|
||||||
|
def list_cubed(array):
|
||||||
|
"szczescian elementow listy"
|
||||||
|
result = 0
|
||||||
|
length = len(array)
|
||||||
|
if length == 0:
|
||||||
|
return result
|
||||||
|
else:
|
||||||
|
while length > 0:
|
||||||
|
result += pow(array[length - 1], 3)
|
||||||
|
length -= 1
|
||||||
|
return result
|
14
intro/Task108.py
Normal file
14
intro/Task108.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""Rozwiązanie zadania 107."""
|
||||||
|
|
||||||
|
def pokemon_speak(string):
|
||||||
|
"upper case"
|
||||||
|
index = 0
|
||||||
|
result = ''
|
||||||
|
for char in string:
|
||||||
|
if index % 2 == 0:
|
||||||
|
result += char.upper()
|
||||||
|
else:
|
||||||
|
result += char
|
||||||
|
return result
|
12
intro/Task109.py
Normal file
12
intro/Task109.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""Rozwiązanie zadania 107."""
|
||||||
|
|
||||||
|
def count_yes_lines(filename):
|
||||||
|
"policz linie"
|
||||||
|
result = 0
|
||||||
|
with open(filename, 'r') as text:
|
||||||
|
for line in text:
|
||||||
|
if line == "YES\n":
|
||||||
|
result += 1
|
||||||
|
return result
|
Loading…
Reference in New Issue
Block a user