Posts by Antony Gabriel • 820 points
32 posts
-
1
votes1
answer79
viewsA: Write to a multi-line output in Javascript (document that opens in browser)
Don’t forget that we are talking about HTML, so to skip a line just use the tag responsible for this, which is the tag <br />, being like this: <script> var n1 = window.prompt('Digite um…
-
0
votes2
answers1184
viewsA: Extract object list from JSON
hmm... What you have there is not quite an Array, but you can do more or less like this: var objetos = { docs : { 0: {_id: "produto-1", descricao: "--", referencia: "--"}, 1: {_id: "produto-2",…
-
0
votes1
answer66
viewsA: Problem in Creating a responsive menu
I’m not the best person to answer that, but I’ll try to contribute: You can create an Interval that will update every X time and will check the screen size, when the width reach such value, the…
-
4
votes4
answers837
viewsA: Problems with conditional structures
Just change that: if conceito == "A" or "B" or "C": resultado = "Aprovado!" elif conceito == "D" or "E": resultado = "Reprovado" for that reason: if conceito == "A" or conceito == "B" or conceito ==…
-
3
votes3
answers2758
viewsA: How to print without line break in Python
Just add end='' and ready! Detail, added the line: from __future__ import print_function to put the parentheses in the print because I couldn’t add the end='' without the parentheses. the end it has…
-
5
votes6
answers49406
viewsA: how to search for an element in a list that is inside another list?
This code seems long, but it’s only because I tried to do something you could understand: lista = [['julian', '0', '5'], ['ana', '10', '4']] print(lista) procurar = input("Digite quem você procura:…
-
1
votes3
answers21057
viewsA: read text file and generate lists for each line with element separation
f = open("texto.txt",'r') texto = f.readlines() x = 0 while x < len(texto): if texto[x] == "\n": local = texto.index(texto[x]) texto.pop(local) else: texto[x] = texto[x].split(',') x += 1 # Esse…
-
0
votes3
answers966
viewsA: How to store an int and a complete string from within an input?
It can also be made that way, similar to the one you tried. Separating quantity and product from comma. numero,alimento = input("> ").split(', ') print(numero) print(alimento) exit: >>>…
-
5
votes1
answer183
viewsA: How to search within Python code
You can use a dictionary to do what you want, see: v = { 'Celular':"200", "Bolsa":"200", "Garrafa":"2" } # Os valores também podem ser inteiros r = input("Digite o valor do produto: ") # Desde que…
-
1
votes2
answers1459
viewsA: Delete and Query Python function
the function consultarLivro is resolved as follows: adding range(len(livro)). This solves why the list index only works with numbers and not with strings that’s what you were doing. Example:…
-
2
votes4
answers457
viewsA: 4x4 matrix with 20 elements
Well, you were doing some things wrong, look at my code I made based on your: What you did wasn’t actually being a matrix, just the input of values and then the comparison. Look what I’ve done: I…
-
1
votes1
answer456
viewsA: Problem with my Hangman game - Python
Good, now I really understood what the problem was and now I edited to fix. Follows the code: Pay attention to what I did, because I don’t even know what I really did. But the result is perfect.…
pythonanswered Antony Gabriel 820 -
0
votes1
answer912
viewsA: Take off or move a frame in Tkinter(python)?
Amid self.frame1['bg'] = '#B5B5B5' and self.frame2 = Frame(principal) put this: self.frame3 = Frame(principal) # Crio um terceiro frame que ficará entre o 1 e o 2 self.frame3.pack()…
-
2
votes3
answers68693
viewsA: How to create a python array
I did it using random values, but instead random in the variable n you can use input() to define them. import random def matriz(n_linhas, n_colunas): matriz = [] # Matriz linha = [] # Linha while…
-
7
votes1
answer132
viewsA: Different types of python dictionaries
First I get the keys ( d.keys() ) and turn it into a list, then I take the first element ( of value 0, 'Ano; Dia; Mes' ) and separate them from "; " getting a list : ['Ano', 'Dia', 'Mes']. Then I do…
-
2
votes1
answer1022
viewsA: Send or Update button in Tkinter (Python) and Widgets Resizing
I had posted a solution that I had found to know when the box was checked, but now I edited it because I found the correct shape, which is even quite similar to the one I had put here. The…
-
2
votes1
answer7183
viewsA: Tkinter Window Management (Python)
you can use .pack_forget() to delete the widget you gave .pack() and then give .pack() in another widget that you would like to be in that frame. Example: I hope I’ve been clearer with this example.…
-
1
votes1
answer255
viewsA: Problem using vowel lists and even numbers
Well, the mistake there was that you did not declare the input as whole int(), then the comparison always went wrong, because I was comparing '2'(str) with 2(int) Another thing I changed was when…
-
5
votes3
answers1815
viewsA: How to start a range from 1
Just put +1 after the i or notas in your case. The variable quantidadeAlunos does not need to exist, the variable Alunos already does that. Thus remaining: Alunos = int(input("Digite quantos alunos…
-
2
votes2
answers897
viewsA: How to delete an element from an Array String?
Your code is a little wrong. He’s deleting according to the i, but if I don’t want to delete the first element? ( 0 ) and yes the second ( 1 )? After all, he deletes what I "eat," right? And also…
-
2
votes2
answers684
viewsA: Tkinter - How to save Entry() string
Well, I changed two things: arq = open("{0}.txt".format(nome_pl), "w") I put . get() at the end of the nome_pl, i gave a read and get() serves to literally get the content, something like that. Then…
-
0
votes4
answers11441
viewsA: A list to receive 20 whole numbers and store in a list and print the largest element in the list
x = 1 lista = [] print('Digite 20 números.') while x <= 20: n = int(input('Digite um número: [ %s ]: '%x)) lista.append(n) x += 1 print('O maior valor é:',max(lista))…
-
4
votes2
answers5610
viewsA: MP3 player with Python
Funny, I just had to move the item += 1 and item -= 1 up, and it worked smoothly. It was just that, you did everything right. def proxima (): for item in range(len(musicas)): item += 1 musica_atual…
-
2
votes2
answers495
viewsA: Type of list elements - Python
Look buddy, I did this one in a hurry : lista1 = [['a', 'bb', 1.5, 3, 'a'],['h', 'oo', 9.6, 2, 'n'],['u', 'pp', 2.9, 1, 'j']] lista2 = ['str', 'float', 'int'] for linha in lista1: for linha2 in…
-
1
votes1
answer1190
viewsA: Generate list/matrix by bringing all combinations of n elements taken p to p in python 3
Here it is: from itertools import permutations import re caracteres = ['A', 'B', 'C', 'D'] for i in permutations(caracteres,2): # 2 elementos i = re.sub(r'\W',"",str(i)) # Retirando outros…
-
-2
votes7
answers49622
viewsA: How to add elements from a list and return the result as an integer?
It’s the sum of all the elements on the list, it’s not? Try this: soma = 0 for i in range(len(l)): soma += l[i] print(soma) Thus remaining: def soma_elementos(lista): l = lista return l l =…
pythonanswered Antony Gabriel 820 -
0
votes2
answers10535
viewsA: How to separate the digits of an integer and add them together? - Python
Try it like this: soma = 0 a = 123 b = str(a) #Transformo em str para poder usar posição. Ex: "b[1] = 2" for i in range(len(b)): soma += int(b[i]) print(soma)
-
0
votes1
answer300
viewsA: Print dictionary using matplotlib
In a dictionary, when you ask only the .keys() or .values() he gives the answer along with a dict_keys or dict_values. That’s what’s happening there in your code, the type number float is coming…
-
0
votes2
answers100
viewsA: Arduino restarting when starting python code execution
The python code is in Python2, would there be a chance that your python would be 3? If it is, the code should have some changes: raw_input now is input and print will have parentheses ( counteúdo )…
-
1
votes2
answers1885
viewsA: How to create a board of user-determined size and present it as text using python?
What I did was something more complex, and with some unnecessary things, but it gets the same result. Because of the spaces, the board can only have 56 columns (I think you can increase this amount…
-
0
votes2
answers4139
viewsA: Program that uses input(). split(" ") and does not run in Python 3.5.1
Here are four ways I know so you can put a value next to each other: C, Q = input('Digite algo: ') lista = [C, Q] Q = int(Q) C = int(C) #Primeira forma - Utilizando a vírgula, bem simples.…
pythonanswered Antony Gabriel 820 -
1
votes4
answers3447
viewsA: Error while trying to write accents in Python files
try the following: str(file.write("Quero caféééééééé!")).encode(encoding='UTF-8',errors='strict') I had a similar problem today and solved so I hope I helped.