Questions tagged as 'python-2.x'

2
answers

Iterate a list and save it in a file

I am trying to iterate a list and then save it to a file .txt with open/write . lista = ['uno', 'dos', 'tres'] mi_path = "../fichero.txt" f = open(mi_path, 'a+') for i in lista: f.write(i) f.close() I give the attribut...
asked by 12.07.2017 / 11:59
1
answer

Error entering data with input ()

This is my code, which I run in Python 2.7.13: print "hola" hiola = input() if hiola == salsa: print "hola" And the error that throws me is the following: Traceback (most recent call last): File "C:\Programacion\Python\hola.py", li...
asked by 17.05.2017 / 21:03
1
answer

I do not understand how Or works in python I refer to the following code

Someone can help me because and how it works in python because I try to do it according to the documentation and it gives me different results import operator operator.or_(2,8) 10 operator.or_(8,2) 10 8 | 2 10 2 | 8 10 2 or 8 2 2 | 8 10...
asked by 04.01.2019 / 16:04
2
answers

Attempt of Eratosthenes sieve in python

Hi, I'm trying to make a code using the Eratosthenes Screen method but I get confused in the part of multiplying and eliminating the number that is not prime, the teacher says we should use a del or something to eliminate the number what is in t...
asked by 19.10.2018 / 05:32
2
answers

Delete files with Python

I'm trying to make a bash adaptation (the Linux terminal) in Windows, for this I'm using Python. #-*- coding: utf-8 -*- import subprocess import os if __name__ == '__main__': wt = True while wt: cmd = str(raw_input("{}>".for...
asked by 27.03.2018 / 01:12
1
answer

How to delete characters in python console? [closed]

Something like in java that I think is with a \b but in python     
asked by 30.10.2016 / 19:24
1
answer

multithreading chronometer in python

I am doing a project for the school in which I have to program software that helps children improve their spelling: #-*- coding: utf-8 -*- import random import subprocess def corrector(pbien, tup): if tup == pbien: return 1 e...
asked by 27.03.2018 / 03:09
2
answers

Unify 2 functions to read files with python

Since some time ago I am trying to make a bash simulator using python, I am creating the tail and head commands, for this create 2 functions: def head(textfile): content = [] try: file = open(textfile, "r") for line in...
asked by 28.05.2018 / 21:09
2
answers

Backtracking Algorithm with conditional Python

I am trying to solve an exercise that I think is quite simple, given a list, print all the possible combinations / permutations of x elements. That is, take out all possible combinations but give a filter for the results. At the moment I have...
asked by 07.12.2016 / 12:30
2
answers

Pyramid of numbers in python

I must make a pyramid that something like this  n = 5 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 but what I try to do gives me that way number n: 6 0 1 2 3 4 5 0 1 2 3 4 5 1 2 3 4 5 2 3 4 5 3 4 5 4 5 5 6 this is the code nu...
asked by 16.10.2018 / 05:15