Posts by Breno • 978 points
27 posts
-
2
votes1
answer455
viewsA: Calculator in python
There are several errors in your code, I can quote at first the fact that the return must receive only the value that must return. What are you trying to do with the return r == a+b, for example, it…
-
0
votes1
answer21
viewsA: I am learning about the Tkinter library, but my code is giving this error"'type' Object is not subscriptable"
The mistake seems to be on this line: bt2["command"] = partial[bt_click, bt2] You are using as if it were a dictionary (of two keys?), while on the first occasion you called as a function. Switch to…
python-3.xanswered Breno 978 -
6
votes2
answers208
viewsQ: What is the actual implementation of "in" in Python?
This week I found myself wondering what the actual implementation of "in" in Python is. To try to answer, I went to look the official documentation about his details, and only say that: For…
-
0
votes1
answer525
viewsA: Printing specific attributes of a python XML file tag
Not about the uses of the other methods, but whenever I used this module, the function I used to mount the tree was fromstring, that receives a string in XML format and returns the root of the tree.…
-
0
votes3
answers732
viewsA: Write a function that returns the larger of two numbers passed as arguments
For the purpose of good practice, I will add this answer. The ideal would be to receive the input, process it and print the result in different functions or places. But since your code is small, no…
python-3.xanswered Breno 978 -
0
votes2
answers10417
viewsA: How do I multiply two matrices in python?
You can use the function zip and the list comprehension. The zip function takes lists and builds a list of tuples with the list members. And list comprehension is a quicker way to write loops is…
-
1
votes2
answers250
viewsA: How to print and save to a TXT
The ideal would be to save what would be these prints to a variable and then save to a file. For example: textoParaSalvar = '''Informe o CNPJ: %s Resumo do Chamado: %s Nome do correspondente: %s…
-
4
votes3
answers2609
viewsA: What is python’s " "?
Before we look at this, it’s good before we study operators bit by bit. Bit-by-bit operators are forms of operators as well as +, -, * or / sane arithmetic operators. To begin with, we know that the…
-
2
votes2
answers98
viewsA: How to pass a Dict within a function, to be used in any case if necessary?
You can (and should) add two more arguments to function: oldKey and newKey. So, when you call this function, you can now modify with dynamic data. def ChangeDictKey(dictionary, oldKey, newKey):…
-
1
votes2
answers193
viewsA: Capture Json information using Python
Note that the data type of planeta['results'][0] is a dictionary. This means, that I can then search for the ['name'] key (which is the one holding the value Tatooine). x =…
-
1
votes2
answers580
viewsA: How to collect data in web Crapping in Python?
You are not using urllib, at least not in practice. You just imported it and saw no use of it in any program code. On the contrary, I saw a code written requests.get(url) Which means you’re trying…
-
4
votes2
answers1055
viewsA: Elaboration of cipher in python
Hello. Well, your code is pretty messed up. Also, it has many irregularities that cannot happen or that are extremely redundant. I can name the two I saw when I read your code: Two Ifs for same…
-
3
votes2
answers745
viewsA: take a string string string string string string string [PYTHON]
Even if I haven’t put enough information in, I’ll demonstrate how easy it is to do this with the Beautifulsoup. Beautifulsoup is a webscrapping-focused library in HTML and XML data search. Use is…
-
2
votes1
answer51
viewsA: What’s the difference between . / and .. / in php?
In this case, the problem is not PHP itself. But in the nomenclatures of these special classes to designate a path. Single point (.) represents the folder itself, that is, the path you are already…
-
2
votes3
answers82
viewsA: How to display matrix input values without [' ']
You can use the method .join() string. The use is # STRING.join(LISTA) # Exemplo: print( ".".join(['192', '168', '0', '1'])) # result: 192.168.0.1 But in your case, just put it in the print lines:…
-
1
votes2
answers1928
viewsA: Add values in a list
By complementing the @Viniciusfarias comment, if you want to add multiple items from one list to another list at a time, you can use the method .extend(). Its use would be something like: lista =…
-
1
votes4
answers388
viewsA: How can I add a hyphen between all even numbers of a value?
I found another approach in pure Python, quite similar to @Andersoncalos iteration code. In it, I repeat each item from 0 to penultimate, adding this number to the output. And I check that both item…
-
8
votes1
answer115
viewsA: Doubt strings Pyhton
There are some details you should be aware of: The original alphabet you are using is that of the module string, in case the string.ascii_uppercase. What gives you the letters of the alphabet in…
-
6
votes1
answer1432
viewsQ: Translation of programming languages
Whenever I search about "translation of programming language in Google" I only get tutorials of how to rewrite from one language to another, and never what I really want to know: Is there any…
characteristic-languageasked Breno 978 -
1
votes1
answer75
viewsA: Error executing "module" code
The return of input is string. To fix, you must convert using int() Thus: num = int(input("Digite um número: "))…
-
10
votes2
answers213
viewsA: Death Note in Python - Loop Sentinel of Death
Your code does not have a loop, just a check with if. In order for it to return to itself, we must apply a loop. More precisely a while loop. The loop while is a type of loop that repeats until the…
-
7
votes3
answers6345
viewsA: How to turn upper-case and lower-case letters into upper-case letters in Python?
I don’t believe you have a specific function for that. But like good language worth its salt, it has two functions to work with this type of problem. The first function is to .upper() which returns…
-
3
votes2
answers487
viewsA: Closing a loop, with enter
Just fixing your code it will work tbm: while True: a = str(input("")) if a == "": break
-
0
votes1
answer111
viewsQ: Is it possible to compare items without if?
I now challenged myself little to develop a function that returns if a number is greater than 5 without the use of any comparison operator, as assertion, while, ternary operator, if which directly…
-
1
votes1
answer42
viewsQ: Wxpython: Getfocuseditem() returning item even with nothing focused
I’m writing an interface with wxPython, but I’ve come across a problem so far with no solution, even looking at the documentation. I have a Listctrl with several items that should be sent to the…
-
1
votes1
answer3097
viewsQ: How to create a Parser in Python?
For a project with file handling, I wanted to convert from "CFG" to "XML", and I believe that in Python I have no support for either of these two types. There was a colleague who made the…
-
5
votes1
answer499
viewsQ: Python "Attributeerror: __exit__" problem
In a group, I asked them to give me tips on some program to test my knowledge. He told me to create a program that reads a file called "arquive.txt" and manages files CHAR and STAGE, with the file…