from snippets import safe_input limit_fines={ "soft":{"limit":10,"fine":5}, "hard":{"limit":None,"fine":15} } limit = safe_input("Podaj limit predkosci (km/h) ") velocity = safe_input("Podaj predkosc pojazdu (km/h) ") difference = velocity-limit over_soft_limit = 0 if difference<limit_fines["soft"]["limit"] else difference-limit_fines["soft"]["limit"] if(over_soft_limit): fine= (over_soft_limit) *limit_fines["hard"]["fine"] fine+= limit_fines["soft"]["limit"]*limit_fines["soft"]["fine"] else: fine=difference*limit_fines["soft"]["fine"] print("Mandat: {0}".format(fine))
from math import sqrt from snippets import safe_input a = safe_input("Podaj a ") b = safe_input("Podaj b ") c = safe_input("Podaj c ") roots = [] print("{0}x^2 + {1}x + {2} = 0".format(a, b, c)) if (a == 0): roots.append(-(c / b)) else: delta = b**2 - 4 * a * c if (delta < 0): print("Brak pierwiastkow rzeczywistych") exit() if (delta == 0): roots.append((-1 * b) / (2 * a)) else: delta_sqrt = sqrt(delta) roots.append(((-1 * b) + delta_sqrt) / 2 * a) roots.append(((-1 * b) - delta_sqrt) / 2 * a) print(*roots, sep="\n")
from snippets import safe_input user = 1 numbers = [] while (user != 0): user = safe_input("Podaj liczbe: ") numbers.append(user) numbers.pop() print("Rezultat: Liczb={0}, Suma={1}, Srednia={2}".format( len(numbers), sum(numbers), sum(numbers) / len(numbers)))
from snippets import safe_input number = safe_input("Podaj liczbe: ", convert_to_int=True) number_binary = [number] while (number_binary[0] != 1): number_binary.append(number_binary[0] % 2) number_binary[0] //= 2 print("{0}(10)=".format(number), end="") print(*number_binary, sep="", end="(2)\n")
centuries={ "0":1900, "1":1900, "2":2000, "3":2000, "4":2100, "5":2100, "6":2200, "7":2200, "8":1800, "9":1800, } year=centuries[month_string[0]] year+=int(year_string) return year PESEL="" while(len(PESEL)!=11): PESEL=str(safe_input("Podaj prawidlowy PESEL: ","PESEL musi byc liczba")) check_obj={ "year":PESEL[0:2], "month":PESEL[2:4], "day":PESEL[4:6], "serial":PESEL[6:10], "gender":PESEL[9], "control":PESEL[10] } #for v in check_obj: # print("{0} : {1}".format(v,check_obj[v])) print("Rok: {0}".format(check_year(check_obj["year"],check_obj["month"]))) print("Płeć: {0}".format(check_gender(check_obj["gender"])))
from snippets import safe_input user_input = safe_input("Podaj liczbe ") if (user_input < 0): print("Liczba {0} jest ujemna".format(user_input)) else: print("Liczba {0} jest dodatnia".format(user_input))
from snippets import safe_input dog_age = safe_input("Podaj wiek psa: ") first_year = 10.5 first_year_years = 2 next_year = 4 age_in_human_years = 0 if (dog_age - 2 > 0): age_in_human_years = first_year * first_year_years age_in_human_years += (dog_age - 2) * next_year else: age_in_human_years = -(dog_age - 2) * first_year print("Wiek psa w ludzkich latach to {0} lata".format(age_in_human_years))
from snippets import safe_input user = safe_input("Podaj wiek: ") if (user > 120 or user < 18): print("Podany wiek jest nieprawidlowy") else: print("Podany wiek jest prawidlowy")
from snippets import safe_input a = safe_input("Podaj dzielna: ") b = safe_input("Podaj dzielnik (nie moze byc zerem (0)): ") try: print("{0}/{1}={2}".format(a, b, a / b)) except ZeroDivisionError: print("Dzielenie przez zero")
import snippets as s number = s.safe_input("Podaj liczbe: ") for i in range(1, 11): print("{0} x {1} = {2}".format(number, i, i * number))
from snippets import safe_input numbers=[ safe_input("Podaj pierwsza liczbe: "), safe_input("Podaj druga liczbe: "), safe_input("Podaj trzecia liczbe: "), ] numbers.sort() #in-place FUJ print("Mediana wynosi {0}".format(numbers[1]))
def print_square(a=1, b=1, char="*"): #top print(char * b) #middle for i in range(a - 2): print("{0}{1}{2}".format(char, " " * (b - 2), char)) #bottom print(char * b) import snippets as s a = s.safe_input("Podaj a: ") b = s.safe_input("Podaj b: ") print_square(a, b)