Beispiel #1
0
 def init(self):
     os.system('clear')
     self.number_of_players = utils.input_number('Number of players: ')
     self.number_of_decks = utils.input_number('Number of decks: ')
     self.table_bet = utils.input_number('Initial table bet: ')
     self.five_card_rule = utils.input_boolean('Activate five card rule: ')
     self.players = [
         Player(i) for i in range(1, self.number_of_players + 1)
     ]
     self.deck = Deck(self.number_of_decks)
     self.dealer = Dealer()
Beispiel #2
0
def solve(stage):
    position, label = get_position_or_label(stage, display(stage))
    if position is not None:
        print_command(f'position {position}')
    else:
        print_command(f'label {label}')
    if stage < 5:
        if label is None:
            label = input_number('Label: ', size=1)
        else:
            position = input_number('Position: ', size=1)
        next_button(position, label)
        print()
Beispiel #3
0
 def module_library(self, clear):
     # ekran biblioteki schematów zadań, dostępny kreator i edycja zadań w bibliotece
     clear()
     print("<< Wciśnij 0 by wrócić\n")
     print(
         "Witaj w bibliotece zadań!\nTutaj możesz tworzyć i edytować zadania."
     )
     print("Oto Twoje zadania:")  # ewentualne katalogi TU
     for module in self.available_modules:
         module.print_module()
     print("\nCo chcesz teraz zrobić?  (liczba + enter)")
     print("0. Wróć do poprzedniego ekranu")
     print("1. Edytuj zadanie")
     print("2. Dodaj zadanie")
     print("3. Usuń zadanie")
     menu_option = -1
     while menu_option not in range(0, 4):
         menu_option = input_number(">> ")
         if menu_option == 1:
             self.edit_module()
         if menu_option == 2:
             self.add_module()
         if menu_option == 3:
             self.delete_module()
             pass
         if menu_option == 0:
             return
Beispiel #4
0
 def edit_module(self):
     # edytuj moduł (czyli "duże" zadanie)
     print("Jakie zadanie chcesz edytować? (podaj numer od 1 do " +
           str(len(self.available_modules)) + ")")
     chosen_module = -1
     while chosen_module not in range(1, len(self.available_modules) + 1):
         chosen_module = input_number(">> ")
     chosen_module -= 1
     self.available_modules[chosen_module].print_module()
     print("Chcesz dodać nową nazwę? (t, n)")
     edit = 'z'
     while edit not in ['t', 'n']:
         edit = input(">> ")
     if edit == 't':
         self.available_modules[chosen_module].name = input(
             "Wprowadź nazwę\n>> ")
     print("Chcesz dodać nowy obraz? (t, n)")
     edit = 'z'
     while edit not in ['t', 'n']:
         edit = input(">> ")
     if edit == 't':
         self.available_modules[chosen_module].image = input(
             "Wprowadź link do obrazu\n>> ")
     print("Chcesz dodać nowy opis? (t, n)")
     edit = 'z'
     while edit not in ['t', 'n']:
         edit = input(">> ")
     if edit == 't':
         self.available_modules[chosen_module].description = input(
             "Wprowadź opis\n>> ")
Beispiel #5
0
 def process_code(n):
     code = input_number(f'Code {n}: ', 6)
     matches = set()
     root = digital_root(code)
     if root == 8:  # digital root is 8
         matches.add(0)
     if sqrt(n) == int(sqrt(code)):  # perfect square
         matches.add(1)
     if code % 7 == 0:  # divisible by 7
         matches.add(2)
     if (code % 5) % 2 == 1:  # modulo 5 is odd
         matches.add(3)
     if root == 3 or root == 4:  # digital root is 3 or 4
         matches.add(4)
     if code % 6 == 0:  # divisible by 6
         matches.add(5)
     if root == 7:  # digital root is 7
         matches.add(6)
     if code % 9 == 0:  # divisibile by 9
         matches.add(7)
     if root == 5:  # digital root is 5
         matches.add(8)
     if (code % 6) % 2 == 0 or code**(1 / 3) == int(
             code**(1 / 3)
     ):  # modulo 6 is even (Standard version) or perfect cube (No Copyright version)
         matches.add(9)
     return matches
Beispiel #6
0
 def delete_module(self):
     #usunięcie zadania z biblioteki
     print("Jakie zadanie chcesz usunąć? (podaj numer od 1 do " +
           str(len(self.available_modules)) + ")")
     chosen_module = -1
     while chosen_module not in range(1, len(self.available_modules) + 1):
         chosen_module = input_number(">> ")
     chosen_module -= 1
     del self.available_modules[chosen_module]
Beispiel #7
0
def download_model(bucket, model_name, models_folder):
    s3 = boto3.resource('s3')
    conn = sqlite3.connect(database)
    cur = conn.cursor()
    # check model availability in database
    try:
        cur.execute(
            "Select rowid, name, version from model_info where name='{}' and available=1;"
            .format(model_name))
        result = cur.fetchall()
        if result:
            if len(result) == 1:
                model_id = result[0][0]
            else:
                print('You have more than one model with such a name:')
                print([res for res in result])
                model_id = input_number(
                    'Input model id you want to download (Enter 0 to Cancel):\n'
                )
        else:
            print(
                'You don\'t have model with provided name, exiting without any changes'
            )
            sys.exit()
    except (sqlite3.DatabaseError, sqlite3.OperationalError,
            sqlite3.ProgrammingError):
        print('Problems while checking model info in database... Try again!')
        sys.exit(1)

    # Check if directory exists
    if not os.path.isdir(models_folder):
        print('New directory for models has been created.')
        os.makedirs(models_folder)
    else:
        model = os.path.isfile('{}{}'.format(models_folder, model_name))
        if model:
            confirmation = confirm_input(
                'Model with such name exists, do you want to replace (y/n)?\n')
            if not confirmation:
                print('Exiting without changes...')
                sys.exit()

    # download model from cloud:
    try:
        model_to_download = 'model_{}_{}'.format(model_name, model_id)
        print(model_to_download)
        s3.Object(bucket_name=bucket,
                  key=model_to_download).download_file('{}/{}'.format(
                      models_folder, model_name))
    except:
        print('Problems with model download from cloud... Try again!')
        sys.exit()

    print('Your model downloaded successfully!')
Beispiel #8
0
def arts():
    ARTISTS = {
        'Bob Ross': (1942, 1995),
        'Picasso': (1881, 1973),
        'Da Vinci': (1452, 1519),
        'Van Gogh': (1853, 1890)
    }
    images = Image.open('./images/Samsung_Google_Arts.png')
    images.show()
    shown = ask('Is the displayed painting shown in the table?')
    if not shown:
        digit = input_number('Last digit of Serial#: ')
    else:
        pos = 0
        while pos == 0 or pos == 5:
            pos = input_number(
                'Position of Arts app on the home screen (1-9 reading order): ',
                size=1)
        artist = ''
        artists = set(map(str.lower, ARTISTS.keys()))
        print_info(', '.join(ARTISTS.keys()))
        while artist.lower() not in artists:
            artist = input("Identify the artist of the painting: ")
        artist_name = capitalize_all(artist)
        artist = ARTISTS[artist_name]
        n = 0
        while n < 1 or n > 5:
            n = input_number("Displayed Painting's Index (1-5): ", size=1)
        if pos < 5:
            birth_year = str(artist[0])
            digit = int(birth_year[pos - 1])
        else:
            death_year = str(artist[1])
            digit = int(death_year[pos - 5 - 1])
        if ask(f'Displayed Artist is {artist_name}?'):
            digit += 2 * (n - 1)  # nth even digit in 0-9
        else:  # lying
            digit += 2 * (n - 1) + 1  # nth odd digit in 0-9
    save('Arts', digit % 10)
Beispiel #9
0
 def add_module(self):
     # dodaj zadanie do biblioteki
     name = input("Wprowadź nazwę\n>> ")
     image = input("Wprowadź link do obrazu\n>> ")
     description = input("Wprowadź opis\n>> ")
     print("Ile kroków chcesz dodać do zadania?")
     num = input_number(">> ")
     tasks = []
     for i in range(num):
         nam = input("Wprowadź nazwę kroku\n>> ")
         imag = input("Wprowadź link do obrazu\n>> ")
         descript = input("Wprowadź opis\n>> ")
         tasks.append(Task(nam, imag, descript))
     self.available_modules.append(Module(tasks, name, image, description))
Beispiel #10
0
 def program_loop(self):
     # główna pętla sterująca programu
     exit_program = True
     clear = lambda: os.system('cls')
     while exit_program is True:
         clear()
         print("Wybierz aktywność:  (liczba + enter)")
         print("0. Zakończ program")
         print("1. Kalendarz")
         print("2. Biblioteka nagród")
         print("3. Biblioteka zadań")
         print("4. Podsumowanie")
         menu_option = input_number(">> ")
         if menu_option == 1:
             self.calendar_view(clear)
         if menu_option == 2:
             clear()
             print(
                 "Oto Twój zbiór naklejek.\n\n(W tym miejscu w aplikacji zostaną wyświetlone\nfoldery z naklejkami, "
                 "które mogą zdobywać podopieczni)\n")
             for award in self.available_awards:
                 print(award.name, award.image)
             input("\nNaciśnij dowolny klawisz by wrócić.")
             clear()
         if menu_option == 3:
             self.module_library(clear)
         if menu_option == 4:
             clear()
             print(
                 "Oto hub podsumowujący.\n\n(W tym miejscu w aplikacji zostaną wyświetlone statystyki,\n"
                 "podsumowanie postępów, zdobyte nagrody i skończone zadania.)"
             )
             done_modules = self.schedule.get_done_modules()
             for date in done_modules.keys():
                 print(date.strftime("%d/%m/%Y"))
                 for as_module in done_modules[date]:
                     print(" - ",
                           as_module.module.name,
                           ": ",
                           as_module.award.name,
                           sep="")
             input("\nNaciśnij dowolny klawisz by wrócić.")
             clear()
         if menu_option == 0:
             exit_program = False
Beispiel #11
0
 def program_loop(self):
     # główna pętla sterująca programu
     exit_program = True
     clear = lambda: os.system('cls')
     while exit_program is True:
         clear()
         print("Cześć! :)")
         print("Oto Twoje dzisiejsze wyzwania!", end='\n\n')
         today = datetime.date.today()
         self.schedule.show_tasks_from_date(today)
         print("+---------------------------------")
         print(
             "\n//do celów testowych: wprowadź 0 by zakończyć, 1 by wejść w zadanie, 2 by wejść w trofea."
         )
         print(
             "Docelowy interfejs również umożliwia wejście jedynie w obszar trofeów i w aktualne zadanie."
         )
         menu_option = -1
         while menu_option not in range(0, 3):
             menu_option = input_number(">> ")
             if menu_option == 0:
                 exit_program = False
             elif menu_option == 1 and self.schedule.current_module != None:
                 self.enter_task(clear, today)
                 print("Gratulacje! Zadanie wykonane!")
                 input("\nNaciśnij dowolny klawisz by wrócić.")
             elif menu_option == 1 and self.schedule.current_module == None:
                 print("Nie masz dziś do wykonania więcej zadań :)")
             elif menu_option == 2:
                 clear()
                 print(
                     "Oto Twoje zdobyte nagrody!\n\n(W tym miejscu w aplikacji zostaną wyświetlone naklejki,\n"
                 )
                 done_modules = self.schedule.get_done_modules()
                 for date in done_modules.keys():
                     print(date.strftime("%d/%m/%Y"))
                     for as_module in done_modules[date]:
                         print(" - ",
                               as_module.module.name,
                               ": ",
                               as_module.award.name,
                               sep="")
                 input("\nNaciśnij dowolny klawisz by wrócić.")
                 clear()
Beispiel #12
0
 def enter_task(self, clear, today, first_task=True, nav=0):
     # wejście do zadania i rozpoczęcie postępu. Funkcja rekurencyjna do nawigacji
     # i oznaczania postępu (czynność po czynności jest odhaczana jako wykonana)
     assigned_module_entered = self.schedule.schedule_dict[today][
         self.schedule.current_module]
     task_name = assigned_module_entered.module.tasks_list[nav].name
     task_img_url = assigned_module_entered.module.tasks_list[nav].image
     task_done = False
     reprint = True
     while reprint:
         clear()
         if nav < assigned_module_entered.which_task_to_do:
             task_done = True
         if task_done:
             print(FULL_SCREEN_UPPER_done)
         else:
             print(FULL_SCREEN_UPPER)
         centerer = int((FULL_SCREEN_COUNT - len(task_name)) / 2)
         for air in range(0, centerer):
             if air == (centerer - 3) and first_task == False:
                 print("<", end="")
             else:
                 print(" ", end="")
         print(task_name + "   >")
         centerer = int((FULL_SCREEN_COUNT - len(task_img_url)) / 2)
         for air in range(0, centerer):
             print(" ", end="")
         print(task_img_url)
         if first_task:
             print(FULL_SCREEN_LOWER_first)
         else:
             print(FULL_SCREEN_LOWER)
         answ = -1
         while answ not in range(1, 3):
             answ = input_number(">> ")
         if answ == 1 and first_task == False:
             return True  # cofa i true reprint
         elif answ == 2 and task_done == False:
             if self.schedule.make_progress():
                 return False  # gdy nie chcemy ponownego wyswietlenia
             else:
                 reprint = self.enter_task(clear, today, False, nav + 1)
         elif answ == 2 and task_done == True:
             reprint = self.enter_task(clear, today, False, nav + 1)
Beispiel #13
0
 def calendar_view(self, clear):
     #wyświetlenie kalendarza (docelowo), domyślnie widok dzienny. Możliwośc dodawania zadań wybranego dnia.
     clear()
     print("\nCo chcesz wyświetlić?  (liczba + enter)")
     print("1. Chcę zobaczyć zadania na dziś")
     print("2. Chcę samemu wybrać datę")
     chosen_date = None
     menu_option = -1
     while menu_option not in range(1, 3):
         menu_option = input_number(">> ")
         if menu_option == 1:
             chosen_date = datetime.date.today()
         if menu_option == 2:
             clear()
             day = input_number("Podaj dzień: ")
             month = input_number("Podaj miesiąc: ")
             year = input_number("Podaj rok: ")
             chosen_date = datetime.date(year, month, day)
     clear()
     print("<< Wciśnij 0 by wrócić\n")
     print("Oto Twój kalendarz! :)\nOto zadania zaplanowane na dziś:")
     print(chosen_date.strftime("%d/%m/%Y") + "\n")
     self.schedule.show_tasks_from_date(chosen_date)
     print("+---------------------------------")
     print("\nWybierz aktywność:  (liczba + enter)")
     print("0. Wróć do poprzedniego ekranu")
     print("1. Zaplanuj zadanie")
     print("2. Przejdź do widoku miesiąca")
     menu_option = -1
     while menu_option not in range(0, 3):
         menu_option = input_number(">> ")
         if menu_option == 1:
             order = 0
             length_l = len(
                 self.schedule.schedule_dict[chosen_date]
             ) if chosen_date in self.schedule.schedule_dict else 0
             if length_l < 1:
                 order = 1
             while order not in range(1, length_l + 2):
                 order = input_number(
                     "Podaj, na którym miejscu ma pojawić się nowe zadanie (od 1 do "
                     + str(length_l + 1) + "): ")
             self.create_assigned_module_view(clear, chosen_date, order)
             return
         if menu_option == 2:
             self.schedule.show_tasks_from_month(chosen_date)
             input("\nNaciśnij dowolny klawisz by wrócić.")
         if menu_option == 0:
             return
Beispiel #14
0
def remove_from_cloud(bucket, model_name):
    s3 = boto3.resource('s3')
    conn = sqlite3.connect(database)
    cur = conn.cursor()
    # change model availability in database
    try:
        cur.execute(
            "Select rowid, name, version from model_info where name='{}' and available=1;"
            .format(model_name))
        result = cur.fetchall()
        if result:
            if len(result) == 1:
                model_id = result[0][0]
            else:
                print('You have more than one model with such a name:')
                print([res for res in result])
                model_id = input_number(
                    'Input model id you want to delete (Enter 0 to Cancel):\n')
            cur.execute(
                "Update model_info set available=0 where rowid={}".format(
                    model_id))
        else:
            print(
                'You don\'t have model with provided name, exiting without any changes'
            )
            sys.exit()
    except (sqlite3.DatabaseError, sqlite3.OperationalError,
            sqlite3.ProgrammingError):
        print('Problems with updating model status in database... Try again!')
        sys.exit(1)

    # delete model from cloud:
    try:
        model_to_delete = 'model_{}_{}'.format(model_name, model_id)
        s3.Object(bucket_name=bucket, key=model_to_delete).delete()
    except:
        print('Problems with deleting model from cloud... Try again!')
        sys.exit()

    conn.commit()
    print('Your model deleted successfully!')
Beispiel #15
0
 def create_assigned_module_view(self, clear, chosen_date, order):
     # kreator nowego zadania z datą, czyli utworzenie obiektu zadania "wykonywalnego"
     # na podstawie zadań z biblioteki
     clear()
     print("<< Wciśnij 0 by wrócić\n")
     print("Utwórz nowe zadanie.")
     print("Wybierz zadanie z Twoich zadań:")  # ewentualne katalogi TU
     counter = 1
     for module in self.available_modules:
         print(str(counter) + '.', end=' ')
         counter += 1
         module.print_module()
     counter = -1
     while counter not in range(1, len(self.available_modules) + 1):
         counter = input_number(
             "\nPamiętaj, że nowe zadania możesz tworzyć w bibliotece zadań.\nWybierz numer od "
             "1 do " + str(len(self.available_modules)) + ": ")
     counter -= 1
     self.schedule.add_module(chosen_date, self.available_modules[counter],
                              order)
     clear()
     print("\nTwoje zadanie zostało utworzone!\n")
     input("\nNaciśnij dowolny klawisz by wrócić.")
     return
Beispiel #16
0
# source: https://www.practicepython.org/exercise/2014/04/30/13-fibonacci.html
from utils import input_number

input_num = input_number(
    'How many numbers do you wish to yeild the Fibonacci numbers?')
num0 = 0
num1 = 1
numbers = [num0, num1]

for i in range(1, input_num):
    num = num0 + num1
    numbers.append(num)
    num0 = num1
    num1 = num

print('List of {} Fibonacci numbers!'.format(input_num))
print(numbers)
Beispiel #17
0
    funni -= len(get_divisors(n, UNFUNNY))
    # If the number is even subtract one funni point, otherwise add 1 funni point.
    if n % 2 == 0:
        funni -= 1
    else:
        funni += 1
    # If the number is prime, add 2 funni points.
    if is_prime(n):
        funni += 2
    # If the number is a perfect square, subtract 2 funni points.
    root = sqrt(n)
    if root == int(root):
        funni -= 2
        # If the number is the square of a prime, subtract another 2 funni points.
        if is_prime(root):
            funni -= 2
    print_info(funni)
    return funni > 0


if __name__ == "__main__":
    try:
        print_info('Press Ctrl+C to cancel')
        for i in range(5):
            if is_funny(input_number('Number: ')):
                print_command('funny')
            else:
                print_command('unfunny')
    except KeyboardInterrupt:
        pass
Beispiel #18
0
 def set_cash(self):
     return utils.input_number('{}\'s initial cash: '.format(self.name),
                               float_=True)
Beispiel #19
0
while True:
    login = input("Enter username: "******"":
        break
    password = input("Enter password: "******"Incorrect username/password")
        continue
    user = users[login]

    while True:
        print("1 - list all tasks")
        print("2 - add new task")
        print("3 - delete task")
        print("4 - logout")
        action = input_number("Select an action: ", MIN_ACTION, MAX_ACTION)
        if action == 1:
            list_tasks(user)
        elif action == 3:
            print("Your tasks: ")
            i = 1
            for task in user[USR_TASKS]:
                print(f'{i}: {task[TASK_NAME]}')
                i += 1
            to_delete_index = input_number("Select a task to delete: ", 1,
                                           len(user[USR_TASKS]) + 1)
            delete_task(users, tasks, user[USR_TASKS][to_delete_index - 1])
            save_data(users, tasks, FILE_NAME)
        elif action == 2:
            new_task = input_new_task()
            if new_task:
Beispiel #20
0
# source: https://www.practicepython.org/exercise/2014/02/15/03-list-less-than-ten.html
from utils import random_list, input_number
a = random_list(100, 100)
num = input_number(
    'Give me a number and I\'ll print a list of numbers that are smaller than that given number:'
)
print('Original list:')
print(a)
print('Numbers that are smaller than {}:'.format(num))
print([x for x in a if x < num])
Beispiel #21
0
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# https://ktane.timwi.de/HTML/Prime%20Checker.html

from math_utils import is_prime
from utils import input_number, print_info, print_command

if __name__ == "__main__":
    try:
        print_info('Press Ctrl+C to cancel')
        while True:
            n = input_number('Number: ')
            if is_prime(n):
                print_command('prime')
            else:
                print_command('not prime')
    except KeyboardInterrupt:
        pass
Beispiel #22
0
# source: https://www.practicepython.org/exercise/2014/02/05/02-odd-or-even.html
from utils import input_number

num = input_number(
    'Give me a number and I\'ll say whether this is an odd or even number:')
if num % 2 == 0:
    print('This number is even!')
else:
    print('This number is odd!')
Beispiel #23
0
# source: https://www.practicepython.org/exercise/2014/01/29/01-character-input.html
from utils import input_number
from datetime import date

print('Give me your name:')
name = input()
age = input_number('Give me your age:')
print(date.today().year - age)
year = (date.today().year - age) + 100
print('{}, you\'ll turn 100 years old in {}.'.format(name, year))