示例#1
0
def divided_by_and_3_5_7():
    """Program to check if number is divided by 3 and 5 and 7 at the same time."""
    from time import sleep
    from dzien_2.repeat_y_or_n import repeat_y_or_n
    from dzien_2.check_if_good import check_if_good

    print(
        'Hello! This program is going to check if provided number is divided by 3 and 5 and 7.'
    )
    sleep(1.5)

    number = None
    number = check_if_good(number, int, 'Please provide number: ')
    number = int(number)
    result = 0

    for i in (3, 5, 7):
        if number % i == 0:
            result += 1

    if result == 3:
        print(f'{number} is divided by 3 and 5 and 7 at the same time!')
    else:
        print(f'{number} is NOT divided by 3 and 5 and 7 at the same time :(.')

    sleep(1)
    repeat_y_or_n(divided_by_and_3_5_7)
示例#2
0
def dog_years():
    """Program to calculate how old is dog in their age's scale."""
    from time import sleep
    from dzien_2.repeat_y_or_n import repeat_y_or_n
    from dzien_2.check_if_good import check_if_good

    print('Hello! This program is calculating how old is dog in their age\'s scale.')
    sleep(1.5)

    scale = [10.5, 4]

    age = None
    age = check_if_good(age, float, 'Please provide number of dog years in human scale: ')
    # while True:
    #     age = input('Please provide number of dog years in human scale: ')
    #     try:
    #         age = float(age)
    #         break
    #     except:
    #         print('It is not a number! Please provide correct number.')
    #         continue

    if age <= 2:
        dog_age = age * scale[0]
        print (f"Your dog's age in dog scale is {dog_age} years.")
    else:
        dog_age = 2 * scale[0] + (age-2)*scale[1]
        print (f"Your dog's age in dog scale is {dog_age} years.")
    repeat_y_or_n(dog_years)
示例#3
0
def pyramid_draw():
    """Script to draw a pyramid consist of #, with given height."""
    from time import sleep
    from dzien_2.repeat_y_or_n import repeat_y_or_n
    from dzien_2.check_if_good import check_if_good

    print(
        'Hello! This program is drawing a pyramid consist of #, with given height. '
    )
    sleep(1.5)

    height = None
    height = check_if_good(height, int,
                           'Please provide height of the pyramid: ')

    # while True:
    #     height = input('Please provide height of the pyramid: ')
    #     try:
    #         height = int(height)
    #         break
    #     except:
    #         print('Please provide integer number!')
    #         continue

    width = 2 * height + 1

    for i in range(height):
        a = 2 * i + 1
        line = '#' * a
        print(line.center(width))

    repeat_y_or_n(pyramid_draw)
示例#4
0
def rectangle():
    """This program is going to draw a rectangle based on provided dimensions."""
    import time
    from dzien_2.repeat_y_or_n import repeat_y_or_n
    from dzien_2.check_if_good import check_if_good
    print(
        "Hello! This program is going to draw a rectangle based on provided dimensions."
    )
    time.sleep(2)

    while True:
        width = None
        width = check_if_good(width, int,
                              'Please provide width of rectangle: ')
        if width == 0:
            print('Width cannot be 0! Please correct it!')
            continue
        else:
            break

    while True:
        length = None
        length = check_if_good(length, int,
                               'Please provide length of rectangle: ')
        if length == 0:
            print('Length cannot be 0! Please correct it!')
            continue
        else:
            break

    elements = ['|', '-', '+', ' ']

    print(elements[2], (width - 2) * elements[1], elements[2])
    for i in range(length - 2):
        print(elements[0], (width - 2) * elements[3], elements[0])
    print(elements[2], (width - 2) * elements[1], elements[2])

    repeat_y_or_n(rectangle, "Would you like to draw another rectangle?")
示例#5
0
def remainder_of_cash():
    """Program to calculate remainder from money in PLN"""
    from time import sleep
    from dzien_2.repeat_y_or_n import repeat_y_or_n
    from dzien_2.check_if_good import check_if_good

    print(
        'Hello! This program is calculating remainder from your money (PLN).')
    sleep(1.5)

    coins = [5, 2, 1, 0.5, 0.2, 0.1]

    money = None
    money = check_if_good(
        money, float,
        'Please provide amount of money to calculate remainder: ')
    # while True:
    #     money = input('Please provide amount of money to calculate remainder: ')
    #     try:
    #         money = float(money)
    #         break
    #     except:
    #         print('Wrong cash amount. Please correct it! ')
    #         continue

    for i in coins:
        check_modulo = lambda x: round(x % i, 1)
        check_div = lambda x: x / i
        if check_modulo(money) == 0 and check_div(money) != 0:
            # print('ahoj') just to show if the if block was used
            print(f'{i:>3} PLN: {check_div(money)}')
            money = money - i * check_div(money)
            if money == 0:
                break
        elif check_modulo(money) != 0 and check_div(money) != 0:
            div_floor = lambda x: x // i
            print(f'{i:>3} PLN: {div_floor(money)}')
            # print(check_modulo(money)) #just to check current number
            money = check_modulo(money)
            if money == 0:
                break
        elif check_modulo(money) == 0 and check_div(money) == 0:
            print('You have typed 0 as cash amount!')
            break
        elif check_modulo(money) != 0 and check_div(money) == 0:
            print('Impossible condition. How did you call it?!')
            break

    sleep(1)
    repeat_y_or_n(repeat_y_or_n)
示例#6
0
def surface_area_of_circle():
    """Simple script to calculate surface area of circle, based on provided radius."""

    import math
    import time
    from dzien_2.check_if_good import check_if_good
    from dzien_2.repeat_y_or_n import repeat_y_or_n

    print(
        "Hello! This program is going to calculate surface area of circle, based on provided radius."
    )
    time.sleep(1.5)

    radius = None
    radius = check_if_good(radius, float,
                           "Please provide value of circle radius [cm]: ")
    pattern = round(math.pi, 5) * (radius**2)

    print(
        f'Following pattern is going to be used to calculate surface area: pi*(radius**2)'
    )
    print(
        'Please write "y" if you would like to see calculations step by step. Write "n" if you want only result'
    )
    while True:
        user_choice = input()
        if user_choice == 'y':
            print(
                f'Step one: substitution of your value to the pattern: \nP=pi*({radius}**2)'
            )
            print(
                f'Step two: calculating results..\nPi constant is estimated to {round(math.pi,5)}.'
            )
            print(
                f'Result: Surface area of circle with radius {radius} cm is equal to {round(pattern,2)} cm\u00b2.'
            )
            break
        elif user_choice == 'n':
            print(
                f'Result: Surface area of circle with radius {radius} cm is equal to {round(pattern,2)} cm\u00b2.'
            )
            break
        else:
            print('Wrong answer! Please write "y" or "n".')
            continue
    repeat_y_or_n(surface_area_of_circle,
                  "Would you like to calculate another circle area?")
示例#7
0
def fahrenheit_to_celsius():
    """This program is converting degrees from Fahrenheit scale to Celsius one."""
    import time
    from dzien_2.repeat_y_or_n import repeat_y_or_n
    from dzien_2.check_if_good import check_if_good

    print('Hello in the simple Fahrenheit to Celsius degrees converter!')
    time.sleep(1.5)

    fahrenheit = None
    fahrenheit = check_if_good(fahrenheit, float,
                               'Please provide value of Fahrenheit degrees: ')

    # while True:
    #     fahrenheit = input("Please provide value of Fahrenheit degrees: ")
    #
    #     try:
    #         fahrenheit = float(fahrenheit)
    #         break
    #     except:
    #         print('Wrong data format! Did you provide a number?')
    #         continue

    pattern = (float(fahrenheit) - 32) / 1.8
    print(f'Following pattern is going to be used for conversion: (℉-32)/1.8.')

    print(
        'Please write "y" if you would like to see calculations step by step. Write "n" if you want only result'
    )
    while True:
        user_choice = input()
        if user_choice == 'y':
            print(
                f'Step one: substitution of your value to the pattern: \n℃=({fahrenheit}-32)/1.8'
            )
            print('Step two: calculating results..')
            print(f'Result: {fahrenheit}℉ is equal to {round(pattern,2)}℃.')
            break
        elif user_choice == 'n':
            print(f'Result: {fahrenheit}℉ is equal to {round(pattern,2)}℃.')
            break
        else:
            print('Wrong answer! Please write "y" or "n".')
            continue
    repeat_y_or_n(fahrenheit_to_celsius,
                  "Would you like to convert another Fahrenheit degree?")
示例#8
0
def if_even():
    """Program to check if provided number is even or not."""
    from dzien_2.repeat_y_or_n import repeat_y_or_n
    from dzien_2.check_if_good import check_if_good
    from time import sleep

    print(
        'Hello! This program is going to check if provided number is even or not.'
    )
    sleep(1.5)
    number = None
    number = check_if_good(number, float, 'Please provide number: ')
    if float(number) % 2 == 0:
        print('Your number is even!')
        repeat_y_or_n(if_even)

    else:
        print('Your number is odd!')
        repeat_y_or_n(if_even)
示例#9
0
def is_leap_year():
    """This program is going to check if provided year is a leap-year or not."""
    from time import sleep
    from dzien_2.repeat_y_or_n import repeat_y_or_n
    from dzien_2.check_if_good import check_if_good

    print('Hello! This program is going to check if provided year is a leap-year or not.')
    sleep(1.5)

    year = None
    year = check_if_good(year, int, 'Please provide a year: ')
    year = int(year)

    if (year % 4 ==0 and year % 100 != 0) or year % 400 == 0:
        print(f'{year} is a leap-year.')
    else:
        print(f'{year} is NOT a leap-year.')

    repeat_y_or_n(is_leap_year)
示例#10
0
def first_last():
    """Simple script to show first and last digit of provided number"""
    import time
    from dzien_2.repeat_y_or_n import repeat_y_or_n
    from dzien_2.check_if_good import check_if_good

    print(
        "Hello! This program is going to show first and last digit of provided number."
    )
    time.sleep(3)

    number = None
    number = check_if_good(number, str, "Please provide a number: ")
    first_digit = number[0]
    last_digit = number[-1:]
    print(f'Your number is {number}.')
    print(f'First digit of yoy number is {first_digit}.')
    print(f'Last digit of you number is {last_digit}.')

    repeat_y_or_n(first_last, 'Would you like to work with another number?')
示例#11
0
def celsius_to_fahrenheit():
    """This program is converting degrees from Celsius scale to Fahrenheit one."""
    import time
    from dzien_2.repeat_y_or_n import repeat_y_or_n
    from dzien_2.check_if_good import check_if_good

    print('Hello in the simple Celsius to Fahrenheit degrees converter!')
    time.sleep(1.5)

    celsius = None
    celsius = check_if_good(celsius,float,"Please provide value of Celsius degrees: ")

    # while True:
    #     celsius = input("Please provide value of Celsius degrees: ")
    #
    #     try:
    #         celsius = float(celsius)
    #         break
    #     except:
    #         print('Wrong data format! Did you provide a number?')
    #         continue

    pattern = float(celsius) * 1.8 + 32

    print(f'Following pattern is going to be used for conversion: ℃*1.8+32.')
    print('Please write "y" if you would like to see calculations step by step. Write "n" if you want only result.')
    while True:
        user_choice = input()
        if user_choice == 'y':
            print(f'Step one: substitution of your value to the pattern: \n℉={celsius}*1.8+32')
            print('Step two: calculating results..')
            print(f'Result: {celsius}℃ is equal to {round(pattern,2)}℉.')
            break
        elif user_choice == 'n':
            print(f'Result: {celsius}℃ is equal to {round(pattern,2)}℉.')
            break
        else:
            print('Wrong answer! Please write "y" or "n".')
            continue
    repeat_y_or_n(celsius_to_fahrenheit, "Would you like to convert another Celsius degree?")
示例#12
0
def divided_by_or_3_5_7():
    """Program to check if number is divided by 3 or 5 or 7"""
    from time import sleep
    from dzien_2.repeat_y_or_n import repeat_y_or_n
    from dzien_2.check_if_good import check_if_good

    print(
        'Hello! This program is going to check if provided number is divided by 3 or 5 or 7.'
    )
    sleep(1.5)

    number = None
    number = check_if_good(number, int, 'Please provide number: ')
    number = int(number)

    for i in (3, 5, 7):
        if number % i == 0:
            print(f'{number} is divided by {i}.')
        else:
            print(f'{number} is not divided by {i}.')
    sleep(1)
    repeat_y_or_n(divided_by_or_3_5_7)
示例#13
0
def multitool():
    """Interface for all created programs that allow user to choose interesting one."""
    from dzien_2.check_if_good import check_if_good
    from dzien_2.repeat_y_or_n import repeat_y_or_n
    from dzien_2.zad_1 import celsius_to_fahrenheit
    from dzien_2.zad_2 import fahrenheit_to_celsius
    from dzien_2.zad_3 import surface_area_of_circle
    from dzien_2.zad_4 import first_last
    from dzien_2.zad_5 import rectangle
    from dzien_2.zad_6b import binary_to_decimal_int
    from dzien_2.zad_7 import if_even
    from dzien_2.zad_8 import divided_by_or_3_5_7
    from dzien_2.zad_9 import divided_by_and_3_5_7
    from dzien_2.zad_10 import is_leap_year
    from dzien_3.zad1 import table_print, create_list
    from dzien_3.zad2 import remainder_of_cash
    from dzien_3.zad3 import pyramid_draw
    from dzien_3.zad4 import dog_years
    from dzien_5.text_stat_creator import text_stat_creator

    print_programs_list()

    user_choice = None
    user_choice = check_if_good(
        user_choice, int,
        "Please provide number of program that you want to run: ")
    user_choice = int(user_choice)

    if user_choice == 1:
        celsius_to_fahrenheit()
        #print(celsius_to_fahrenheit.__doc__)
    elif user_choice == 2:
        fahrenheit_to_celsius()
    elif user_choice == 3:
        surface_area_of_circle()
    elif user_choice == 4:
        first_last()
    elif user_choice == 5:
        rectangle()
    elif user_choice == 6:
        binary_to_decimal_int()
    elif user_choice == 7:
        if_even()
    elif user_choice == 8:
        divided_by_or_3_5_7()
    elif user_choice == 9:
        divided_by_and_3_5_7()
    elif user_choice == 10:
        is_leap_year()
    elif user_choice == 11:
        table_print(create_list())
    elif user_choice == 12:
        remainder_of_cash()
    elif user_choice == 13:
        pyramid_draw()
    elif user_choice == 14:
        dog_years()
    elif user_choice == 15:
        text_stat_creator()
    else:
        print('Wrong number!')

    repeat_y_or_n(multitool, 'Would you like to repeat Multitool program?')
示例#14
0
def control():
    """
    Function to allow user interact with diary.
    :return:
    """
    file_directory = input(
        'Please provide absolute directory of diary file.\n'
        'If file do not exist, it is going to be created automatically.\n'
        'Your file directory: ')
    diary = Diary(file_directory)
    diary.menu()
    decision = None
    decision = check_if_good(decision, int, 'What is your choice? ')
    decision = int(decision)

    if decision == 1:
        print('Here are your diary entries:')
        if diary.all_entries is None:
            print('Your diary is empty!')
        else:
            count = 0
            for i in range(diary.number_of_all_entries):
                count += 1
                print(f'Entry {count}:')
                single = SingleEntry(i, diary.file)
                print(single)
                # for x, y in i.items():
                #     print(x + ': ' + y)
        diary.open_diary.close()
    elif decision == 2:
        print('Adding new entry...')
        diary.add_entry()
        diary.open_diary.close()
    elif decision == 3:
        print('Procedure of removing entries started.')
        print(
            f'Number of all entries in diary is equal to {diary.number_of_all_entries}.'
        )
        entry_number_to_remove = int(
            input('Provide number of entry to remove: '))
        diary.remove_entry(entry_number_to_remove)
        diary.open_diary.close()
    elif decision == 4:
        print('Search mode on.')
        search_mode = int(
            input(
                'Would you like to search by content(1) or date(2)? Please provide number. '
            ))
        if search_mode == 1:
            keyword = input('Please type keyword to search: ')
            diary.search(keyword)
        elif search_mode == 2:
            date = input(
                'Please provide date to search in diary. Format is: DD-MM-YYYY. '
            )
            diary.date_validation(date)
            diary.search_by_date(date)
        else:
            print('Wrong number!! ')
        diary.open_diary.close()
    elif decision == 5:
        exit()