indentation

Convert entire (Python) file from 2-space indent to 4-space indent

Convert entire (Python) file from 2-space indent to 4-space indent Question: I regularly work with Python files that are provided to me as templates, which use an indentation of 2. However, I personally prefer working with an indentation width of 4, which is what I’ve set in my .vimrc. However, because of the indentation-sensitivity of …

Total answers: 4

IndentationError: expected an indented block while printing

IndentationError: expected an indented block while printing Question: I keep getting indentation errors when I print out stuff in python inp = input(‘You are at crossways, where do you want to go? type "left" or "right"’) if inp is ‘left’: print("You didn’t die. Do you want to wait for a ship or wait for a …

Total answers: 1

SyntaxError: invalid non-printable character U+00A0 in python

SyntaxError: invalid non-printable character U+00A0 in python Question: I’m getting the error: SyntaxError: invalid non-printable character U+00A0 When I’m running the code below: # coding=utf-8 from PIL import Image   img = Image.open("img.png") I have tried to load different images with different formats (png, jpg, jpeg). I have tried using different versions of the Pillow …

Total answers: 1

Unexpected indentation when return in python

Unexpected indentation when return in python Question: when I try to return but I got an error in 2nd return signup_result & return login_result https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportUndefinedVariable "return" can be used only within a functionPylance here is utils.py class CognitoResponse(object): def __init__(self, access_token, refresh_token, cognito_user_id=None): self.access_token = access_token self.refresh_token = refresh_token self.cognito_user_id = cognito_user_id def cognito_signup(username: str, …

Total answers: 1

python calculator indentation error (cant seem to get the program working)

python calculator indentation error (cant seem to get the program working) Question: I just started python yesterday so I was trying to make this python code to make a calculator that adds, multiplies, divides, and subtracts. When I started testing the code just wasn’t working even though I did similar things and to me, the …

Total answers: 2

Removing initial whitespace plus the last empty new line line using python

Removing initial whitespace plus the last empty new line line using python Question: I am trying to implement a code that prints an 8 by 8 matrix (0 to 63). It should however remove the initial tab spaces and the last empty line. My code is below : s =” for i in range(n): for …

Total answers: 2

Same code with different indentation gives different results?

Same code with different indentation gives different results? Question: Below are codes that differ only in indentation. They give different outputs. The first one outputs array([[7.68717818e+11, 6.97681947e+11, 7.63307666e+11, 6.47349007e+11, 5.99065727e+11], [7.66709788e+11, 6.99939453e+11, 7.64013608e+11, 6.45261906e+11, 5.99177884e+11], [2.94202392e+11, 4.16042886e+12, 3.69055160e+11, 3.08724683e+11, 3.71083543e+11], …, [2.32972294e+11, 2.25518151e+11, 2.16985500e+11, 1.52392619e+11, 1.87686750e+11], [1.31495500e+11, 4.03441481e+11, 1.66796570e+11, 7.37775506e+10, 1.55474795e+11], [1.26216951e+11, 5.60385882e+11, 1.49446146e+11, 7.23769941e+10, …

Total answers: 1

prime numbers in python same programs different outputs

prime numbers in python same programs different outputs Question: I have this assignment where I have to write a code to determine if a number is a prime number or not and I couldn’t come up with a solution so I searched the net and found the following code( the first one) and then I …

Total answers: 2

Why does a set of double quote comment have effect on real code

Why does a set of double quote comment have effect on real code Question: This is the code which be reported error unexpexted indentation(because of the comment YOUR CODE HERE double quoted) while score0 < goal and score1 < goal: if who == 0: num_rolls = strategy0(score0, score1) score0 += take_turn(num_rolls, score1, dice) who = …

Total answers: 2

What is causing "triple quotes" to change the indentation?

What is causing "triple quotes" to change the indentation? Question: I am using triple quotes to create a multiline string: print( ”’ Hello! How are you?”’) Output: Hello! How are you? Inside the string, How is coming exactly underneath Hello. However, I am not able to understand what is causing the indentation to change. Asked …

Total answers: 5