コード例 #1
0
def main():
    Exit = 0
    language = input(
        "Please select your language english(0),spanish(1), french(2) or a diferent language(3)\n"
    )
    messages, library = fn.language_menu(language)
    while Exit != 1:
        while True:
            try:
                search_or_add_input = int(input(messages[1]))
                if search_or_add_input == 0:
                    os.system('cls')
                    title = input(messages[2] + '')
                    author = input(messages[3] + '')
                    year = input(messages[4] + '')
                    location = input(messages[5] + '')
                    descritpion = input(messages[6] + '')
                    language_input = input(messages[23] + '')
                    state = input(messages[24] + '')
                    fn.add(title, author, year, location, descritpion,
                           language_input, state)
                elif search_or_add_input == 1:
                    os.system('cls')
                    while True:
                        category = input(messages[14])
                        try:
                            category = int(category)
                            if category not in range(7):
                                print(messages[0])
                                continue
                            break
                        except:
                            os.system('cls')
                            print(messages[0])
                            continue
                    book = input(messages[15])
                    fn.search(category, book, language)
                else:
                    os.system('cls')
                    print(messages[0])
                    continue
                break
            except:
                os.system('cls')
                print(messages[0])
        while True:
            Exit = input(messages[18])
            try:
                Exit = int(Exit)
                if Exit not in range(2):
                    print(messages[0])
                    continue
                break
            except:
                os.system('cls')
                print(messages[0])

    os.system('cls')
    print('\n' + messages[17])
    time.sleep(8)
コード例 #2
0
def add(new_list):

    New_Pokemon = add(Pokemon_List)

    assert callable(add)
    assert isinstance(add(Pokemon_List), list)
    assert '' not in add(Pokemon_List)
コード例 #3
0
ファイル: app.py プロジェクト: vovm2/Blackjack
def stand():
    user_deck = from_db2arr(UserCards)
    val1 = add(user_deck)

    dealer_deck = from_db2arr(DealerCards)
    val2 = add(dealer_deck)

    if val2 < 17:
        all_deck = from_db2arr(AllDeck)
        while val2 < 17:
            dealer_deck.append(all_deck.pop())
            val2 = add(dealer_deck)

    if val2 > val1 and val2 <= 21:
        msg = "You lose"
    elif val2 == val1:
        msg = "A tied score"
    else:
        msg = "You win!"

    return render_template('main.html',
                           val1=val1,
                           val2=val2,
                           msg=msg,
                           player=user_deck,
                           dealer=dealer_deck)
コード例 #4
0
ファイル: main.py プロジェクト: Cesoneemz/wehelpyoubot
def process_create_new_message(message):
    bad_words = check_bad_words(message.text.lower())
    if bad_words == '':
        add(message)
        bot.send_message(message.chat.id, "Сообщение успешно добавлено!")
    else:
        bot.send_message(
            message.chat.id,
            f"Ваше сообщение содержит недопустимые слово(-а) ({bad_words}) и не было "
            f"добавлено.")
        go_back(message)
コード例 #5
0
ファイル: gui.py プロジェクト: MaximilianKindshofer/podsog
 def add_podcast(self):
     name = self.podcastLineEdit.text()
     feed = self.feedLineEdit.text()
     if len(name) is 0:
         self.msgbox('Dont make it so hard', 'Please add a name')
     elif len(feed) is 0:
         self.msgbox('No feed', 'Please add a feed')
     else:
         podcastItem = QtGui.QListWidgetItem()
         podcastItem.setText(name)
         podcastItem.setToolTip(feed)
         self.podcastList.addItem(podcastItem)
         functions.add(name, feed)
         self.add_dialog.accept()
コード例 #6
0
ファイル: app.py プロジェクト: vovm2/Blackjack
def hit():
    all_deck = from_db2arr(AllDeck)
    user_deck = from_db2arr(UserCards)
    user_deck.append(all_deck.pop())

    to_db(UserCards, user_deck)
    to_db(AllDeck, all_deck)

    dealer_deck = from_db2arr(DealerCards)

    if add(user_deck) > 21:
        val1 = add(user_deck)
        val2 = add(dealer_deck)
        return render_template('main.html', val1=val1, val2=val2, msg="You lose", player=user_deck, dealer=dealer_deck)

    dealer_deck[0] = 'X'
    return render_template('main.html', player=user_deck, dealer=dealer_deck)
コード例 #7
0
def test_add_strings():
    assert functions.add(("hail", "fellow")) == "hailfellow"
    assert functions.add(("well", "met")) == "wellmet"
    assert functions.add(("", "")) == ""
    with pytest.raises(TypeError):
        functions.add(("bad", 1))
    with pytest.raises(TypeError):
        functions.add((1, "bad"))
コード例 #8
0
def testAdd(operands):

    sys.path.append('project/src/calculate-activity')

    import functions as fun

    # invoke the add method for the functions.py file
    test = fun.add(operands[0], operands[1])

    # return the result
    return test
コード例 #9
0
ファイル: app.py プロジェクト: vovm2/Blackjack
def stand():
    user_deck = from_db2arr(UserCards)
    val1 = add(user_deck)

    dealer_deck = from_db2arr(DealerCards)
    val2 = add(dealer_deck)

    if val2 < 17:
        all_deck = from_db2arr(AllDeck)
        while val2 < 17:
            dealer_deck.append(all_deck.pop())
            val2 = add(dealer_deck)

    if val2 > val1 and val2 <= 21:
        msg = "You lose"
    elif val2 == val1:
        msg = "A tied score"
    else:
        msg = "You win!"

    return render_template('main.html', val1=val1, val2=val2, msg=msg, player=user_deck, dealer=dealer_deck)
コード例 #10
0
ファイル: overview.py プロジェクト: keizik/table-football
	def getRanks(self, scores):
		points = self.getPoints(scores)
		games = {}
		for score in scores:
			games = add(games,score.home.id,1)
			games = add(games,score.away.id,1)
		rankDict = []
		for i in range(len(points)):
			team = 0
			pts = -1
			for t, p in points.items():
				if p > pts:
					team = t
					pts = p
				elif p == pts and team!=0 and games[t] < games[team]:
					team = t
					pts = p
			teamObj = Team.objects.get(pk=team)
			rankDict.append({'id': team, 'team': teamObj.name, 'pt': pts, 'games': games[team]}) 
			del points[team]
		return rankDict #returning a dictionary with limitted data instead of full team object
コード例 #11
0
ファイル: commands.py プロジェクト: fcklklfc/engtrain
def command_line(dictionary):
    while True:
        command = input('Enter your command: ')
        if command == 'exit':
            return 'exit'
        elif command == 'move':
            functions.move()
        elif command == 'help':
            for command, description in list(commands_list.items()):
                print(command + ' = ' + description)
        elif command == 'add':
            functions.add()
            return functions.update()

        elif command == 'remove':
            functions.remove()
        elif command == 'print':
            continue
        elif command == 'show':
            functions.show()
        elif command == 'train':
            return functions.train(dictionary)
コード例 #12
0
ファイル: app.py プロジェクト: vovm2/Blackjack
def hit():
    all_deck = from_db2arr(AllDeck)
    user_deck = from_db2arr(UserCards)
    user_deck.append(all_deck.pop())

    to_db(UserCards, user_deck)
    to_db(AllDeck, all_deck)

    dealer_deck = from_db2arr(DealerCards)

    if add(user_deck) > 21:
        val1 = add(user_deck)
        val2 = add(dealer_deck)
        return render_template('main.html',
                               val1=val1,
                               val2=val2,
                               msg="You lose",
                               player=user_deck,
                               dealer=dealer_deck)

    dealer_deck[0] = 'X'
    return render_template('main.html', player=user_deck, dealer=dealer_deck)
コード例 #13
0
def testAdd(x, y):

    #get Directory for functions
    currentworkingdirectory = os.getcwd()
    currentworkingdirectory = currentworkingdirectory.replace('/scripts', '')
    currentworkingdirectory = (currentworkingdirectory + '/project/src')
    sys.path.insert(0, currentworkingdirectory)

    from functions import add

    try:
        output = add(int(x), int(y))
    except:
        output = "ERROR"

    return output
コード例 #14
0
def testAdd(x, y):

	#get Directory for functions
	currentworkingdirectory = os.getcwd()
	currentworkingdirectory = currentworkingdirectory.replace('/scripts', '')
	currentworkingdirectory = (currentworkingdirectory + '/project/src')
	sys.path.insert(0, currentworkingdirectory)

	from functions import add

	try:
		output = add(int(x),int(y))
	except:
		output = "ERROR"

	return output
コード例 #15
0
ファイル: overview.py プロジェクト: keizik/table-football
	def getPoints(sewlf, scores):
		points = {}
		for score in scores:
			if score.home_score > score.away_score:
				points = add(points, score.home.id, 2)
				points = add(points, score.away.id, 0)
			elif score.home_score == score.away_score:
				points = add(points, score.home.id, 1)
				points = add(points, score.away.id, 1)
			else:
				points = add(points, score.home.id, 0)
				points = add(points, score.away.id, 2)
		return points
コード例 #16
0
def main():
  poll = None
  while(poll != "quit"):
    print("What would you like to do? (add, subtract, multiply, divide, quit)")  
    poll = input('>')

    if poll == "add":
      print("Your result is: %d\n\n" % (functions.add(*get_input())))

    elif poll == "divide":
      print("Your result is: %d\n\n" % (functions.divide(*get_input())))

    elif poll == "multiply":
      print("Your result is: %d\n\n" % (functions.multiply(*get_input())))

    elif poll == "subtract":
      print("Your result is: %d\n\n" % (functions.subtract(*get_input())))

    else:
      if not poll == "quit":
        print("Sorry, I didn't understand.")
コード例 #17
0
def test_add():
    day = datetime.date.today().day
    storage = {day: [[100, "out", "pizza"], [1000, "in", "salary"]]}
    add(storage, 150, "out", "jewlery")
    assert get_trans(storage, day, 2) == [150, "out", "jewlery"]
コード例 #18
0
modulefun.add(10,20,30)

import modulefun as mf  # modulefun shpuld be available in the above mentioned path
mf.add(2,5,6)
mf.fib(50)
mf.a

print(mf.a)

from modulefun import add
add(2,5,6)

# Packages

import PYTHON_OCT2018
import functions

functions.

functions.add(11,11,11)

Functions.


modulefun.add(12,12,12)


.modulefun

md.add(4,5,6)
 
コード例 #19
0
 def add():
     functions.add()
コード例 #20
0
 def test_add(self):
     self.assertEqual(add(10, 5), 15)
     self.assertEqual(add(-1, 1), 0)
     self.assertEqual(add(-1, -1), -2)
コード例 #21
0
 def test_add(self):
     result = functions.add(100, 5)
     self.assertEqual(result, 105)
     self.assertEqual(functions.add(100, 1), 101)
コード例 #22
0
def test_sum():
    assert f.add(7, 3) == 10
    assert f.add(-1, -1) == -2
    assert f.add(-1, 1) == 0
    assert f.add(8.9, 9.1) == 18.0
コード例 #23
0
ファイル: run_function.py プロジェクト: mehul-da/Omelia
def run_functions(curr_spreadsheet, query_string, query_parameters):
    print("Query string: " + query_string)
    # ADD <ENTRY_1> <ENTRY_2>
    # <ENTRY_1>: row 4
    commands = query_string.split(".")
    sheet = curr_spreadsheet.sheet
    for i in range(len(commands)):
        args_and_comm = commands[i].split(" ")
        command_name = args_and_comm[0]
        args = []

        for k in range(1, len(args_and_comm)):
            result = args.append(query_parameters[args_and_comm[k]])

        result = None
        
        if command_name == "ADD":
            result = functions.add(sheet, args[0], args[1])
        elif command_name == "INSERTAFT":
            if args[0].rowOrCol == 'col':
                result = functions.insert_entry(sheet, chr(ord(args[0].value) + 1), args[0].rowOrCol)
            else:
                result = functions.insert_entry(sheet, int(args[0].value) + 1, args[0].rowOrCol)
        elif command_name == "INSERTBEF":
            if args[0].rowOrCol == 'col':
                result = functions.insert_entry(sheet, chr(ord(args[0].value)), args[0].rowOrCol)
            else:
                result = functions.insert_entry(sheet, int(args[0].value), args[0].rowOrCol)
        elif command_name == "SET":
            if(isinstance(args[0], float)):
                result = functions.cell_update(sheet, args[1].cell_str, args[0])
            else:
                result = functions.cell_update(sheet, args[1].cell_str, args[0].value)
        elif command_name == "AVG":
            result = functions.average_entry(sheet, args[0].value, args[0].rowOrCol)
        elif command_name == "BOLD":
            if(isinstance(args[0], Cell)):
                result = functions.format_bold(sheet, str(args[0].cell_str) + ":" + str(args[0].cell_str))
            else:
                result = functions.format_bold_entry(sheet, args[0])
        elif command_name == "SET_BG":
            if(len(args) == 2):
                if(isinstance(args[1], Cell)):
                    result = functions.set_background(sheet, args[1].cell_str + ":" + args[1].cell_str, args[0].color_str)
                else:
                    result = functions.set_background_entry(sheet, args[1], args[0].color_str)
            else:
                result = functions.set_background(sheet, str(args[1].cell_str) + ":" + str(args[2].cell_str), args[0].color_str)
        elif command_name == "MULTIPLY":
            if(isinstance(args[1], Entry)):
                result = functions.multiply_entry(sheet, int(args[0].value), args[1].value, args[1].rowOrCol == "row")
            else:
                result = functions.multiply_cell(sheet, int(args[0].value), args[1].cell_str)
        elif command_name == "SIN":
            if(len(args) == 1):
                if (isinstance(args[0], Cell)):
                    result = functions.sin_cell(sheet, args[0].cell_str)
                else:
                    # Don't know if this works
                    result = functions.sin_entry(sheet, ord(args[0].value) - ord("A") + 1, args[0].rowOrCol == "col")
            else:
                result = functions.sin_range(sheet, str(args[0].cell_str) + ":" + str(args[1].cell_str))
        elif command_name == "COS":
            if(len(args) == 1):
                if (isinstance(args[0], Cell)):
                    result = functions.cos_cell(sheet, args[0].cell_str)
                else:
                    result = functions.cos_entry(sheet, args[0].value, args[0].rowOrCol == "col")
            else:
                result = functions.cos_range(sheet, str(args[0].cell_str) + ":" + str(args[1].cell_str))
        elif command_name == "SORT":
            # result = functions.sort(sheet, args[0])
            if(args[0].rowOrCol == 'col'):
                result = functions.sort(sheet, (ord(args[0].value) - ord("A") + 1, 'asc'))
        # elif command_name == "FILTER_EVEN":
        #     result = functions.filter_even(sheet, args[0])
        # elif command_name == "FILTER_ODD":
        #     result = functions.filter_odd(sheet, args[0])
        elif command_name == "FILTER_PRIME":
            result = functions.filter_by_prime(sheet)
        # elif command_name == "MAX_VAL":
        #     result = functions.max_val(sheet, args[0])
        # elif command_name == "NORMALIZE":
        #     result = functions.normalize(sheet, args[0], args[1])
        
        query_parameters["<RES_" + str(i + 1) + ">"] = result
コード例 #24
0
ファイル: test.py プロジェクト: kaustavsenkvs/Travis-
def test_check_add():
    assert add(5, 2) == 7
コード例 #25
0
ファイル: test.py プロジェクト: kaustavsenkvs/Travis-
def test_check_wrong_add():
    assert add(9, 4) == 7
コード例 #26
0
ファイル: main.py プロジェクト: Bardonkle/learntocode
# absolute import
import functions

# relative import
# from functions import add

# relative import with dot syntax, requires __init__.py file
from . import functions

x = 5
y = 6

z = functions.add(x, y)
print("5 + 6 =", z)

z = functions.sub(x, y)
print(z)
コード例 #27
0
 def test_add(self):
     self.assertEqual(4, functions.add(2, 2))
     self.assertEqual(0, functions.add(-2, 2))
     self.assertEqual(-2, functions.add(-1, -1))
コード例 #28
0
 def test_add(self):
     assert functions.add(0, 1) == 1
コード例 #29
0
def ui_add(storage, cmd):
    value = int(cmd[1])
    tr_type = cmd[2]
    description = cmd[3]
    add(storage, value, tr_type, description)
コード例 #30
0
        The following arithmetic operators can be used:
        - For addition, press A
        - For subtraction, press S
        - For multiplications, press M
        - For division, press D
        - For power function, press P
        - To quit, press X
        """)

    op = input("> Enter operator key: ").lower()

    if op == 'x':
        break

    elif op == 'a':
        print("> The answer is: ", f.add(num1, num2))

    elif op == 's':
        in_order = bool(
            int(input(
                ">> Enter 1 -> num1 - num2 OR Enter 0 -> num2 - num1: ")))
        print("> The answer is: ", f.subtract(num1, num2, in_order=in_order))

    elif op == 'm':
        print("> The answer is: ", f.multiply(num1, num2))

    elif op == 'd':
        in_order = bool(
            int(input(">> Enter 1 -> num1 / num2 OR Enter 0 -> num2 / num1")))
        print("> The answer is: ", f.divide(num1, num2, in_order=in_order))
コード例 #31
0
def test_add_integers():
    assert functions.add((1, 1)) == 2
    assert functions.add((1, -1)) == 0
    assert functions.add((2**31, 1)) == 2147483649
コード例 #32
0
ファイル: operations.py プロジェクト: vritt/pycamp2k17
import functions
from functions import subtract
from maths.multiplication import multiplication

if __name__ == '__main__':

    c = functions.add(10, 2)
    print(c)

    d = subtract(20, 10)
    print(d)

    e = multiplication(12, 10)
    print(e)
コード例 #33
0
    def start(self):
        """Starts the server."""
        sock = socket.socket()
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.bind((self.host, self.port))
        sock.listen(1)
        print('Listening on port %s ...' % self.port)

        while True:
            # Accept client
            conn, _ = sock.accept()

            # Receive message
            msg = conn.recv(1024).decode()
            print('Received:', msg)

            # Send response
            # Nivel 1- Invocação de funções
            res1 = functions.hello()
            # Nivel 2 - Nomes das funções
            if msg == "hello":
                res2 = functions.hello()
            elif msg == "hello2":
                res2 = functions.hello2()
            else:
                res2 = 'Error'

            # Nivel 3 - Parametros / Nivel 4 - Multiplos Parametros
            if msg.startswith('greet'):
                values = msg.split()
                name = values[1]
                res3and4 = functions.greet(name)
                #conn.send(res3and4.encode())
            elif msg.startswith('add'):
                values = msg.split()
                a = values[1]
                b = values[2]
                res3and4 = functions.add(eval(a), eval(b))
                #conn.send(str(res3and4).encode())

            # Nivel 5 - JSON
            # Convert json message to dict
            msg = json.loads(msg)
            method = msg['method']
            params = msg['params']

            if method == 'greet':
                res5 = functions.greet(*params)
                result = {"result": str(res5)}
                jsonResult = json.dumps(result)
                #conn.send(jsonResult.encode())
            elif method == 'add':
                res5 = functions.add(*params)
                result = {"result": str(res5)}
                jsonResult = json.dumps(result)
                #conn.send(jsonResult.encode())
            else:
                result = {"error": "Method not found"}
                jsonResult = json.dumps(result)
                #conn.send(jsonResult.encode())

            # Nivel 7 - Funções como objetos

            try:
                func = self.funcs[method]
                res = str(func(*params))
            except KeyError:
                res = 'Error'
                conn.send(res.encode())

            conn.send(res.encode())

            # Close client connection
            conn.close()
コード例 #34
0
import functions

print(functions.add(2, 3))

コード例 #35
0
def test_add():
    assert add(1, 2) == 3
コード例 #36
0
        del line[0]

    #INCREMENTING 'WHILE' COUNTER
    lineCounter += 1

    #FUNCT IDENTIFIER
    funct = line[0]

    #SELECTING FUNCTION
    if funct == 'add':
        #REGISTERS IDENTIFIERS
        reg1 = line[1]
        reg2 = line[2]
        reg3 = line[3]
        #ENTERING FUNCTION
        reg[reg1] = functions.add(reg[reg2], reg[reg3])
    elif funct == 'addi':
        #REGISTERS AND IMMEDIATE IDENTIFIERS
        reg1 = line[1]
        reg2 = line[2]
        immediate = line[3]
        #ENTERING FUNCTION
        reg[reg1] = functions.addi(reg[reg2], immediate)
    elif funct == 'j':
        label = line[1]
        #GOING BACK TO THE LINE WHERE THE LABEL STARTS
        lineCounter = functions.j(label)
    elif funct == 'beq':
        reg1 = line[1]
        reg2 = line[2]
        label = line[3]
コード例 #37
0
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    # function

    functions.print_hi('PyCharm')
    functions.say_hi('Folau')

    # method with return value
    result = functions.is_adult(20)
    print(f'is adult {result}')

    # use built-in methods
    print(math.pow(2, 3))
    print(sqrt(4))

    print(functions.add(1, 2))
    print(functions.multiply(1, 2))

    data_types.showDataTypes()

    if_statements.showIfStatements()

    iteration.show()

    # Arbitrary arguments *
    functions.print_profile("Folau", 30)

    # Keyword Arguments
    functions.print_hi(name="Folau")

    #Arbitrary Keyword Arguments, **kwargs