From f7ff97b3f3170f75c8accf561ae3639c529cae7b Mon Sep 17 00:00:00 2001 From: Grzegorz Rogozik Date: Sun, 12 Jan 2020 13:16:55 +0100 Subject: [PATCH] add pythons exercises --- intro/Task102.py | 16 ++++++++-------- intro/Task104.py | 17 ++++++++++------- intro/Task105.py | 21 +++++++++------------ intro/Task106.py | 18 +++++++++++------- 4 files changed, 38 insertions(+), 34 deletions(-) diff --git a/intro/Task102.py b/intro/Task102.py index c118896..1391e4b 100644 --- a/intro/Task102.py +++ b/intro/Task102.py @@ -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) diff --git a/intro/Task104.py b/intro/Task104.py index a95d06b..e44f482 100644 --- a/intro/Task104.py +++ b/intro/Task104.py @@ -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) diff --git a/intro/Task105.py b/intro/Task105.py index 84663bd..50b25b6 100644 --- a/intro/Task105.py +++ b/intro/Task105.py @@ -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 diff --git a/intro/Task106.py b/intro/Task106.py index 665169b..a155fd6 100644 --- a/intro/Task106.py +++ b/intro/Task106.py @@ -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