# data[].attributes.body
import PySimpleGUI as sg

sg.theme('LightGreen3')

layout = [
    [sg.Text("Aprēķini integrāli! ")],
    [sg.Text("∫50xdx= "), sg.InputText(key='answer1')],       # 50x^2/2
    [sg.Text("∫42x^5dx= "), sg.InputText(key='answer2')],    # 42x^6/6
    [sg.Text("∫9x^2dx= "), sg.InputText(key='answer3')],     # 9x^3/3
    [sg.Text("", size=(0, 1), key='OUTPUT')],
    [sg.Button('OK')]
]

window = sg.Window("Integrālis", layout)

while True:
    event, values = window.read()

    if event in (None, 'Exit'):
        break

    if event == 'OK':

        correct_answers = [50x^2/2,42x^6/6, 9x^3/3]
        user_answers = [int(values['answer1']),int(values['answer3']),int(values['answer3'])]
        percentage = sum(1 for ua, ca in zip(user_answers, correct_answers) if ua==ca)/ len(correct_answers)* 100

        sg.popup(f"Jūsu atbilde ir: {values['answer1']}",
                 f"Jūsu atbilde ir: {values['answer2']}",
                 f"Jūsu atbilde ir: {values['answer3']}",
                 f"Pareizo atbilžu procentos: {percentage}%"
                 )


window.close()

# data[].attributes.body
import PySimpleGUI as sg

sg.theme ('BlueMono')
uzdevumi = [
    ("∫ 5 dx", "5x+C"),
    ("∫ 6 dx", "6x+C"),
]


def evaluate_answer(uzdevums, atbilde):


    pareiza_atbilde = uzdevums[1]

    if atbilde.lower().strip() == pareiza_atbilde.lower().strip():
        return 100
    else:
        return 0



layout = [
    [sg.Text("Nenoteikto integrāļu uzdevumi")],
    [sg.Text("Uzdevums:", size=(15, 1)), sg.Text(uzdevumi[0][0], key='-UZDEVUMS-')],
    [sg.Text("Ievadiet atbildi:", size=(15, 1)), sg.InputText(key='-ATBILDE-')],
    [sg.Button('Pārbaudīt'), sg.Button('Iziet'), sg.Button('Nākamais')],
    [sg.Text(size=(30, 1), key='-RESULT-')],
]

window = sg.Window('Integrāļu uzdevumi', layout)


while True:
    event, values = window.read()


    if event in (sg.WIN_CLOSED, 'Iziet'):
        break
    elif event == 'Pārbaudīt':
        atbilde = values['-ATBILDE-']
        uzdevums = uzdevumi[0]
        rezultāts = evaluate_answer(uzdevums, atbilde)
        window['-RESULT-'].update(f"Rezultāts: {rezultāts:.2f}%")


    if event == 'Nākamais':
        uzdevumi.pop(0)
        if len(uzdevumi) == 0:
            break
        window['-UZDEVUMS-'].update(uzdevumi[0][0])

window.close()

# data[].attributes.body
import PySimpleGUI as sg

layout = [


[ sg.Text('Введите число', size = (40,1), key= '-rez2-')],
[sg.InputText(key='-x-', enable_events=True)],
[ sg.Text('Введите степень числа', size = (40,1), key= '-rez2-')],
[sg.InputText(key='-y-', enable_events=True)],[[sg.Button('Высчитать'),]]
]



window = sg.Window('Integrala aprekinašana', layout)
saraksts = []

while True:
    event, values = window.read()
    if event == sg.WINDOW_CLOSED:
        break
    if event == 'Высчитать':
            num1 = float(values['-x-'])
            num2 = float(values['-y-'])
            result = num1**(num2+1)
            result2 = result /int(num2+1)

            window['-rez2-'].update(f'Summa : {result2} + C')


window.close()

# data[].attributes.body
import PySimpleGUI as sg

layout = [
          [ sg.Text(size = (40,1), key= '-OUTPUT2-')],[sg.InputText(key='-IN-', enable_events=True)],[sg.InputText(key='-IN2-', enable_events=True)],[[sg.Button('X^n+1/n+1'),]]]
window = sg.Window('Skaitļa aprekinašana', layout)
saraksts = []

while True:
    event, values = window.read()
    if event == sg.WINDOW_CLOSED:
        break
    if event == 'X^n+1/n+1':
            num1 = float(values['-IN-'])
            num2 = float(values['-IN2-'])
            result = num1**(num2+1)
            result2 = result /int(num2+1)

            window['-OUTPUT2-'].update(f'Summa : {result2} + C')


window.close() 

# data[].attributes.body
import PySimpleGUI as sg

layout = [
    [sg.Text(size=(50, 2), key='Pz1')],
    [sg.InputText(key= 'count', enable_events = True)],
    [sg.InputText(key= 'count2', enable_events = True)],
    [sg.Combo(['+', '-', '*', '/'], key='operation', enable_events=True)],
    [sg.Text('', key='result')],
]

window = sg.Window('Calk', layout)

def variants(num1, num2, operation):
    if operation == '+':
        return num1 + num2
    elif operation == '-':
        return num1 - num2
    elif operation == '*':
        return num1 * num2
    elif operation == '/':
        if num2 !=0:
            return num1 / num2
        else:
            return "Nevar dalit ar 0!"

while True:
    event, values = window.read()
    if event == sg.WINDOW_CLOSED:
        break
    elif event == 'operation':
        num1 = float(values['count'])
        num2 = float(values['count2'])
        operation = values['operation']
        result = variants(num1, num2, operation)
        window['result'].update(f'Summ = {result}')

# data[].attributes.body
import PySimpleGUI as sg

sg.theme('Reds')

def calculate(num1, num2, operation):


    if operation == '+':
        return num1 + num2
    elif operation == '-':
        return num1 - num2
    elif operation == '*':
        return num1 * num2
    elif operation == '/':
        if num2 == 0:
            return 'Ar nulli dalīt nedrīkst!'
        else:
            return num1 / num2

def display_result(result):


    layout = [[sg.Text(f"Rezultāts: {result:.2f}")]]
    window = sg.Window('Rezultāts', layout)

    while True:
        event, values = window.read()

        if event in (sg.WIN_CLOSED, 'Aizvērt'):
            break

    window.close()

layout = [
    [sg.Text("Ievadiet divus skaitļus un izvēlieties darbību: ")],
    [sg.Input(key='-NUM1-'), sg.Combo(['+', '-', '*', '/'], key='-OPERATION-'), sg.Input(key='-NUM2-')],
    [sg.Button('Aprēķināt'), sg.Button('Iziet')]
]

window = sg.Window('Matemātiskais tests', layout)

while True:
    event, values = window.read()

    if event in (sg.WIN_CLOSED, 'Iziet'):
        break

    if event == 'Aprēķināt':
        try:
            num1 = float(values['-NUM1-'])
            num2 = float(values['-NUM2-'])
            operation = values['-OPERATION-']
            result = calculate(num1, num2, operation)
            display_result(result)
        except ValueError:
            sg.popup("Kļūda! Lūdzu, ievadiet pareizus skaitļus.")

window.close()

# data[].attributes.body
import PySimpleGUI as sg


def calculate(num1, num2, operation):

    if operation == '+':
        return num1 + num2
    elif operation == '-':
        return num1 - num2
    elif operation == '*':
        return num1 * num2

layout = [  [sg.Text('Ievadi skaitļus')],
            [sg.Input(key = '-NUM1-'), sg.Combo(['+', '-','*'], key= '-OPERATION-'), sg.Input(key = '-NUM2-')],
            [sg.Button('Rezultāts')],
            [sg.Text( size=(30, 1), key='-OUTPUT-')]]


window = sg.Window('Math', layout)

while True:

    event, values = window.read()

    if event == sg.WIN_CLOSED :
        break

    if event == 'Rezultāts':

        num1 = int(values['-NUM1-'])
        num2 = int(values['-NUM2-'])
        operation = values['-OPERATION-']

        result = calculate(num1, num2, operation)
        window['-OUTPUT-'].update(f'Rezultāts ir : {result}')


window.close()

# data[].attributes.body
import PySimpleGUI as sg

layout = [
          [ sg.Text(size = (15,1), key= '-OUTPUT2-')],[sg.InputText(key='-IN-', enable_events=True)],[sg.InputText(key='-IN2-', enable_events=True)],[[sg.Button('-'),sg.Button('/'),sg.Button('*'),sg.Button('+')]]]
window = sg.Window('Skaitļa aprekinašana', layout)
saraksts = []

while True:
    event, values = window.read()
    if event == sg.WINDOW_CLOSED:
        break
    if event == '+':
            num1 = float(values['-IN-'])
            num2 = float(values['-IN2-'])
            result = num1 + num2
            window['-OUTPUT2-'].update(f'Summa : {result}')
    if event == '-':
            num1 = float(values['-IN-'])
            num2 = float(values['-IN2-'])
            result = num1 - num2
            window['-OUTPUT2-'].update(f'Summa : {result}')
    if event == '/':
            num1 = float(values['-IN-'])
            num2 = float(values['-IN2-'])
            result = num1 / num2
            window['-OUTPUT2-'].update(f'Summa : {result}')
    if event == '*':
            num1 = float(values['-IN-'])
            num2 = float(values['-IN2-'])
            result = num1 * num2
            window['-OUTPUT2-'].update(f'Summa : {result}')


window.close()

# data[].attributes.body
import PySimpleGUI as sg


layout = [  [sg.Text('Ieraksti 1 ciparu'), sg.InputText(key = '-NUM1-', enable_events = True)],
            [sg.Text('Ieraksti 2 ciparu '), sg.InputText(key = '-NUM2-', enable_events = True)],
            [sg.Button('Summa')],
            [sg.Text( size=(30, 1), key='-OUTPUT-')] ]


window = sg.Window('Summa', layout)

while True:

    event, values = window.read()



    if event == sg.WIN_CLOSED :
        break

    if event == 'Summa':

        num1 = int(values['-NUM1-'])
        num2 = int(values['-NUM2-'])

        result = num1 + num2

        window['-OUTPUT-'].update(f'Summa ir : {result}')


window.close()

# data[].attributes.body
import PySimpleGUI as sg


layout = [[sg.Text("Ievadiet divus skaitļus:")],
          [sg.Input(key='-NUM1-'), sg.Text('+'), sg.Input(key='-NUM2-')],
          [sg.Button('Aprēķināt summu'), sg.Button('Iziet')],
          [sg.Text(size=(30,1), key='-OUTPUT-')]]

window = sg.Window('Matemātiskais tests', layout)


while True:
    event, values = window.read()

    if event == sg.WINDOW_CLOSED or event == 'Iziet':
        break
    if event == 'Aprēķināt summu':
        try:
            num1 = float(values['-NUM1-'])
            num2 = float(values['-NUM2-'])
            result = num1 + num2
            window['-OUTPUT-'].update(f"Summa: {result}")
        except ValueError:
            window['-OUTPUT-'].update("Kļūda! Lūdzu, ievadiet pareizus skaitļus.")

window.close()

# data[].attributes.body
import PySimpleGUI as sg

layout = [[sg.Button('Button 1'),  sg.Button('Button 3')],
          [ sg.Text(size = (15,4), key= '-OUTPUT2-')],[sg.Button('Click Me'), sg.InputText(key='-IN-', enable_events=True)],[ sg.InputText(key='-IN2-', enable_events=True)]]
window = sg.Window('Layout Solution', layout)
saraksts = []

while True:
    event, values = window.read()
    if event == sg.WINDOW_CLOSED:
        break
    if event == 'Click Me':
            num1 = float(values['-IN-'])
            num2 = float(values['-IN2-'])
            result = num1 + num2
            window['-OUTPUT2-'].update(f'Summa : {result}')

window.close()

# data[].attributes.headline
Uztaisīt saskarne ar diviem lodziņiem. Ierakstot skaitļus, programma saskaita skaitļu summu

# data[].attributes.subject
Uztaisīt saskarne ar diviem lodziņiem. Ierakstot skaitļus, programma saskaita skaitļu summu