Posts by Jefferson Carvalho • 726 points
18 posts
-
0
votes2
answers13897
viewsA: How to remove specific position characters from a string?
For this, you can use the Slices. In your case, it would look like this: dado = dado[:5] # Pega do começo até a posição 5 - 1 Remembering that the strings are objects immutable, thus, it is not…
-
2
votes1
answer721
viewsA: How to call a class attribute in another Django class
You can put the instance to the object itself. Example: >>> from abc.models import Perfil, PrimeiroConjunto >>> conjunto = PrimeiroConjunto.objects.get(nome='Alvaro') >>>…
-
7
votes1
answer566
viewsQ: Dynamic Memory Allocation X vector
I was studying this subject in C, and in most of the places I look for, one of the examples of using this resource is when you’re going to create a vector whose size you don’t know. Example: int…
-
1
votes1
answer229
viewsQ: Segmentation fault (core dumped)
There is something wrong with the pointer in this program, which aims to test a function that counts the number of characters in a string. For some reason he can’t access the memory he points to.…
casked Jefferson Carvalho 726 -
0
votes1
answer106
viewsQ: Infinite loop when passing memory addresses
I was doing this code whose goal is to use pointers to fill an array with an arithmetic progression. But I can’t get out of the first loop. int main() { int r, // Razão da PA i, // Contadora pa[10],…
casked Jefferson Carvalho 726 -
4
votes1
answer766
viewsQ: I cannot change the state of an Entry() widget in Python and Tkinter
In my code, my Entry() the state is originally as DISABLED. To enable entry, the user would need to mark one of the checkbuttons. Well, at least that’s the idea. What happens is I mark one of the…
-
3
votes3
answers211
viewsA: How could I improve the code?
I did the following: lista = [0,0,0,0,0] acuNota = 0 arq = open("notas","w") for x in range(5): lista[x]= float(input("Insira uma nota por favor: ")) acuNota += lista[x] print ("Criando arquivo em…
-
1
votes1
answer1855
viewsQ: How to clean the screen on Tkinter?
There is a practical way to "clean" a screen by giving a destroy() in all the widgets at once, without having to do it one by one?
-
2
votes2
answers54
viewsQ: I can’t delete key in dbm
I made a basic program to store some data and I am in trouble if the user chooses the option to delete some stored dictionary key. The function that erases data in my program is this: def…
-
2
votes1
answer1040
viewsQ: Package strings using struct
I’m doing a basic exercise using the module struct, and I came across a problem: To pack a string, we should inform in the method struct.pack() the number of characters it has, right? But what if…
-
3
votes1
answer611
viewsQ: Problem comparing strings and string being broken into two python lines
I was creating a game that scrambles words, and the user has 6 attempts to guess what the word is. I’ll put the code here: import random def main(): while True: input('Presisone enter para sortear…
-
2
votes1
answer1015
viewsQ: Problem handling text files with python
I’m trying to make a hangman game, and for that, I’m taking word lists and putting them in files in format .txt for Python to use in the game. When picking up a list of names of people, have some…
-
4
votes1
answer159
viewsQ: Small doubt with numerical operations
I was doing a python function that gives me the results (x' and x") of bhaskara formula, just to train the logic a little bit. And playing a little bit in the shell, I ended up discovering something…
-
5
votes4
answers7094
viewsQ: Swap the first character of a string with the last python character
I have the following function: def troca(s): letra1 = s[0] letra2 = s[-1] s = s.replace(s[0], letra2) s = s.replace(s[-1], letra1) return s troca ('bar') As you can see, I provide as an argument for…
-
2
votes3
answers1630
viewsQ: Problem with randint function
Hello, I’m having a little problem with my code. I try to generate a list of 4 random integer numbers that do not repeat, but... list_num = [] c = 0 v = random.randint(0, 9) while c < 4 and v not…
-
3
votes1
answer1176
viewsQ: Search for nested list elements
I’m having a problem with a code. I have to find a specific element (I know what element it is, but I don’t know its position, because it is random). Under normal conditions, I would use a index and…
-
3
votes3
answers683
viewsQ: list index out of range when trying to resolve the issue of google Developer day 2010
First of all, I am going to copy here the statement of the question to place: In the quiet village of Ponteironuloville, all the phones have six digits. The phone company establishes the following…
-
13
votes3
answers8700
viewsQ: Typeerror: not all Arguments converted During string formatting (Python 3.4)
I’m new to programming and I’m trying to do a simple code for an exercise to calculate a phone bill: t = float(input('Digite a quantidade de minutos gasta: ')) if t < 200: p = t * 0,2 if t >=…