예제 #1
0
def area(a, b, c):
    if trian(a, b, c) == 'Equilatero':
        A = (rc(3) / 4.00) * (a**2)
        return A
    if trian(a, b, c) == 'Escaleno' or 'Isosceles':
        s = (a + b + c) / 2
        A = (a * ((2.00 / a) * rc(s * (s - a) * (s - b) * (s - c)))) / 2.00
        return A
예제 #2
0
def altura(a, b, c):
    if trian(a, b, c) == 'Equilatero':
        h = (rc(3) / 2.00) * a
        return h
    if trian(a, b, c) == 'Escaleno' or 'Isosceles':
        s = (a + b + c) / 2
        h = (2.00 / a) * rc(s * (s - a) * (s - b) * (s - c))
        return h
예제 #3
0
파일: Problema2.py 프로젝트: 316141952/thc
def tiempos(v, y):
    T = []
    g = 9.81
    import math
    from math import sqrt as rc
    while 0 <= y:
        t1 = (-v + rc(v**2 + 2 * g * y)) / g
        t2 = (-v - rc(v**2 + 2 * g * y)) / g
        T.append(t1)
        T.append(t2)
        return T
예제 #4
0
def tiempo2(v, y):
    g = 9.81
    import math
    from math import sqrt as rc
    while y >= 0:
        t2 = (-v - rc(v**2 + 2 * g * y)) / g
        return t2
예제 #5
0
def tiempo1(v, y):
    g = 9.81
    import math
    from math import sqrt as rc
    while y >= 0:
        t1 = (-v + rc(v**2 + 2 * g * y)) / g
        return t1
예제 #6
0
from math import sqrt as rc

nb = 1
b = 2

while nb < 100000:
    a = 0

    for i in range(2, int(round(rc(nb), 0) + 1)):
        if nb % i == 0:
            a += 1
            break

    #if a == 0: print(nb, "is prime.")
    b = 6 - b
    nb += b
예제 #7
0
def transpile(line):
    splited = line.split(' ', 2)

    # Affichage
    if (splited[0] == 'println!'):
        if (splited[1] == 'str'):
            toShow = splited[2]
            print(toShow)
        if (splited[1] == 'var'):
            instruct = splited[2]
            if (instruct in variables.keys()):
                print(variables[instruct])
            else:
                print('No variable named "' + splited[2] + '"')

    # Variables
    if (splited[0] == 'let'):

        # Input
        if (splited[2] == 'scan()'):
            var = input("> ")
            variables[splited[1]] = var

        # Random
        if (splited[2].startswith('rand()')):
            splitIn = splited[2].split(' ')
            if (splitIn[2] == '->'):
                try:
                    a = int(splitIn[1])
                    b = int(splitIn[3])
                    fin = random.randint(a, b)
                    variables[splited[1]] = fin
                except:
                    print('Please specify two integers')
            else:
                print(
                    'Syntax Error : Did you mean "let <var> rand() <number> -> <number>" ?'
                )

        elif (splited[2] != '' and splited[2] != 'scan()'):
            variables[splited[1]] = splited[2]
            print('Val \'' + str(splited[2]) + '\' assigned to ' +
                  str(splited[1]))

        elif (splited[2] == ''):
            variables[splited[1]] = splited[2]
            print('Variable \'' + str(splited[1] + '\' initialized'))

    # Comparaison de variables
    if (splited[0] == 'comp'):
        if ((splited[1]) in variables.keys()
                and splited[2] in variables.keys()):
            if (variables[splited[1]] == variables[splited[2]]):
                print(splited[1] + '==' + splited[2])
            if (variables[splited[1]] != variables[splited[2]]):
                print(splited[1] + '!=' + splited[2])

    # Calcul de racine carrée
    if (splited[0] == 'sqrt'):
        try:
            nombre = int(splited[1])
            print(rc(nombre))
        except:
            print(
                'You cannot calculate the square root of a string litteral !')
    if (splited[0] == 'sc'):
        print(variables[splited[1]] + variables[splited[2]])

    # Commandes système
    if (splited[0] == 'sys'):
        if (splited[1] == '->'):
            os.system(splited[2])
        else:
            print('Syntax Error : Try out "sys -> <command>"')

    # Exit function
    if (splited[0] == 'quit'):
        exit()

    # Wipe function
    if (splited[0] == 'wipe'):
        print('All variables erased !')
        variables.clear()

    # Opérations mathématiques
    elif (splited[0] != 'println!' and splited[0] != 'let'
          and splited[0] != 'comp' and splited[0] != 'sqrt'
          and splited[0] != 'file' and splited[0] != 'sc'
          and splited[0] != 'sys' and splited[0] != 'quit'
          and splited[0] != 'wipe'):
        if (int(splited[0]) > -32768 and int(splited[0]) < 32768
                and int(splited[2]) > -32768 and int(splited[2]) < 32768):
            arg1 = int(splited[0])
            arg2 = int(splited[2])

            if (splited[1] == '+'):
                print(arg1 + arg2)
            if (splited[1] == '-'):
                print(arg1 - arg2)
            if (splited[1] == '*'):
                print(arg1 * arg2)
            if (splited[1] == '/'):
                print(arg1 / arg2)
            if (splited[1] == '**'):
                origin = arg1
                for i in range(1, arg2):
                    arg1 *= origin
                print(arg1)
        else:
            print('Error, "' + splited[0] + '" doesn\'t exists')
예제 #8
0
def code():
    saisie = input('>>> $ ')
    splited = saisie.split(' ', 2)

    # Conditions
    if (saisie.startswith('if')):
        splited = saisie.split(' ', 4)
        if (splited[1] in variables.keys() and splited[3] in variables.keys()):
            if (splited[2] == '==' and splited[4] == '{'):
                if (variables[splited[1]] == variables[splited[2]]):
                    conditions.con()
                else:
                    pass
            else:
                print('Syntax Error')

        else:
            print('No variable found !')

    # Affichage
    if (splited[0] == 'println!'):
        if (splited[1] == 'str'):
            toShow = splited[2]
            print(toShow)
        if (splited[1] == 'var'):
            instruct = splited[2]
            if (instruct in variables.keys()):
                print(variables[instruct])
            else:
                print('No variable named "' + splited[2] + '"')
        if (splited[1] == 'arr'):
            instruct = splited[2]
            if (instruct in arrays.keys()):
                print(arrays[instruct])

    # Change array or var
    if (splited[0] == 'chng'):

        # Change array
        if (splited[1] == 'arr'):
            arr_name = splited[2]
            print(arrays[arr_name])
            new_value = input('enter new array value\n> ')
            new_value = new_value.split(';')
            arrays[arr_name] = new_value

        # Change var
        if (splited[1] == 'let'):
            var_name = splited[2]
            print(variables[var_name])

            new_value = input('enter new variable value\n> ')
            variables[var_name] = new_value

    # Comments
    if (splited[0] == '#'):
        pass

    # Arrays
    if (splited[0] == 'array'):
        if (splited[2] == 'scan()'):
            print(
                'Enter the characters you want to add to the array.\nuse the separation sign - ";"'
            )
            array = input('> ')
            array = array.split(';')

            arrays[splited[1]] = array

    # Variables
    if (splited[0] == 'let'):

        # Input
        if (splited[2] == 'scan()'):
            var = input("> ")
            variables[splited[1]] = var

        # Random
        if (splited[2].startswith('rand()')):
            splitIn = splited[2].split(' ')
            if (splitIn[2] == '->'):
                try:
                    a = int(splitIn[1])
                    b = int(splitIn[3])
                    fin = random.randint(a, b)
                    variables[splited[1]] = fin
                except:
                    print('Please specify two integers')
            else:
                print(
                    'Syntax Error : Did you mean "let <var> rand() <number> -> <number>" ?'
                )

        elif (splited[2] != '' and splited[2] != 'scan()'):
            variables[splited[1]] = splited[2]
            print('Val \'' + str(splited[2]) + '\' assigned to ' +
                  str(splited[1]))

        elif (splited[2] == ''):
            variables[splited[1]] = splited[2]
            print('Variable \'' + str(splited[1] + '\' initialized'))

    # Comparaison de variables
    if (splited[0] == 'comp'):
        if ((splited[1]) in variables.keys()
                and splited[2] in variables.keys()):
            if (variables[splited[1]] == variables[splited[2]]):
                print(splited[1] + '==' + splited[2])
            if (variables[splited[1]] != variables[splited[2]]):
                print(splited[1] + '!=' + splited[2])

    # Calcul de racine carrée
    if (splited[0] == 'sqrt'):
        try:
            nombre = int(splited[1])
            print(rc(nombre))
        except:
            print(
                'You cannot calculate the square root of a string litteral !')
    if (splited[0] == 'sc'):
        print(variables[splited[1]] + variables[splited[2]])

    # Commandes système
    if (splited[0] == 'sys'):
        if (splited[1] == '->'):
            os.system(splited[2])
        else:
            print('Syntax Error : Try out "sys -> <command>"')

    # Exit function
    if (splited[0] == 'quit'):
        exit()

    # Wipe function
    if (splited[0] == 'wipe'):
        print('All variables erased !')
        variables.clear()

    # Opérations mathématiques
    elif (splited[0] != 'println!' and splited[0] != 'let'
          and splited[0] != 'comp' and splited[0] != 'sqrt'
          and splited[0] != 'file' and splited[0] != 'sc'
          and splited[0] != 'sys' and splited[0] != 'quit'
          and splited[0] != 'wipe' and splited[0] != '#'
          and splited[0] != 'array' and splited[0] != 'chng'):
        if (int(splited[0]) > -32768 and int(splited[0]) < 32768
                and int(splited[2]) > -32768 and int(splited[2]) < 32768):
            arg1 = int(splited[0])
            arg2 = int(splited[2])

            if (splited[1] == '+'):
                print(arg1 + arg2)
            if (splited[1] == '-'):
                print(arg1 - arg2)
            if (splited[1] == '*'):
                print(arg1 * arg2)
            if (splited[1] == '/'):
                print(arg1 / arg2)
            if (splited[1] == '**'):
                origin = arg1
                for _ in range(1, arg2):
                    arg1 *= origin
                print(arg1)
        else:
            print('Error, "' + splited[0] + '" doesn\'t exists')
예제 #9
0
def Fib(n):
    while n > 0:
        n = ((1 + rc(5))**n - (1 - rc(5))**n) / (2**n * rc(5))
        return (n)