Questions tagged as 'python-3.x'

2
answers

SyntaxError: unindent does not match any outer indentation level

What should I do when this error message appears: "SyntaxError: unindent does not match any outer indentation level"? I can not declare the else of the variable. Here is a print of the problem and the code: escada = 'Sim' if escada == 'S...
asked by 29.08.2017 / 00:12
4
answers

Program to find MMC in Python

I was doing a basic exercise for the While function, it asked to create a program that found the MMC between 2 numbers ... I could do it, but the program continues to print the answer non-stop in loop . Where did I go wrong? num1 = int...
asked by 14.09.2017 / 01:43
3
answers

How to simplify these two methods?

Well, in my class there are two magic methods, add and sub: def __add__(self, other): if other.__m == self.__m and other.__n == self.__n: result = [] for i in range(other.__m): lst = [] for j in ra...
asked by 04.12.2018 / 22:21
2
answers

How to use a function inside another function in python3?

I wanted to get the result of the input of the function name and use inside the intro function, however the way I'm trying, I get only one error. code: def nome(): name = str(input('Poderia nos dizer seu nome? ')) return name def i...
asked by 23.11.2018 / 19:16
3
answers

How to use "while not in" in Python?

I tried looping while to check if a condition was met. If the user types 0, 1 or 2 the program should stop asking the user which number he will choose. If the user chooses a number other than 0, 1 or 2, the program will ask the user which number...
asked by 22.05.2018 / 19:25
3
answers

convert a string list to a list of integers

x = ['443' , '552' , '342' , '368' , '9867' , '335' , '9412' , '7436' , '1692' , '85' , '990' , '332' , '8816' , '4567' , '279' , '119' , '2290' , '234' , '9863' , '345' , '230' , '5574' , '230' , '5432'] How can I convert this list to a new...
asked by 22.05.2018 / 21:45
3
answers

How to compress code in python 3?

I wanted to leave this little bit of code in a single line ... i = int(input()) for j in range(1,i+1): if(i%j==0): print(j) Is it possible?     
asked by 13.08.2018 / 21:30
2
answers

Python calling super () on a class that does not implement inheritance

I'm developing some middlewares and delving into the Django source code I came across the following: class MiddlewareMixin: def __init__(self, get_response=None): self.get_response = get_response super().__init__() de...
asked by 05.08.2018 / 21:16
1
answer

What's wrong with this python code?

import urllib.request import time def send_to_twitter(): import sys import tweepy CONSUMER_KEY = '1wrnsF5lB8fEWVzRdvlIqdTl' CONSUMER_SECRET = 'eTiylDUHLJgGnTCcxzzCtzHXG4OlHrbY6wLvuZUnAEhrokyNA' ACCESS_KEY = '2325915097-q2JYaZ...
asked by 06.01.2017 / 16:30
2
answers

Restrict __setattr__ when the attribute does not exist within the instance in Python

Hello, I need to know how I can assemble a class that can not have attributes implemented after the instance. Ex: class Foo(object) def __init__(self, a='hello', b='world') self.a = a self.b = b __setattr__(self, key,...
asked by 06.09.2016 / 19:05