enter image description here
so I keep getting these whitespaces in my output. I have googled but nothing relevant comes back. i have attached my code and my output. can someone tell me what i am doing wrong. I dont have any space in my code, so why is it putting it in my ouput? this is a common problem form me in zybooks and i would really love to know what i am doing wrong so i can get this done and move on to the next assignment without spending 2 hours on a simple exercise.
If you're asking why there are spaces between your outputs of favoriteColor, etc., it's because Python's print function automatically adds spaces between each of its arguments. If you don't want this happening, you can change your code in two ways:
Either add a sep argument to your print, telling Python to add an empty separator between your arguments:
print('\nFirst password:', favoriteColor, chr(95), petName, sep='')
Or, you can append your arguments together yourself, as strings:
print('\nFirst password:', favoriteColor + chr(95) + petName)
Also, I should mention that if you need an underscore, you don't need to call chr(95) -- you can just write the string '_'.
Related
So here is an example of a multiline string in vscode/python:
Cursor is after the p , and then you press enter, and end up like this:
i.e. the string ends up indented, which seems what you almost never want - why have an arbitratly amount of whitespace on the next line of this string ?
Is there any way change this in vscode, i.e. for multiline strings, it should end up with this:
I think this problem is related to different coding styles of different people.
For example,
def example(x):
if x:
a = '''
This is help
'''
def example(x):
if x:
a = '''This is help
'''
The automatic indenting of vscode line breaks is based on code blocks. If you want Vscode can identify multiline string, I think it would be better to submit future request in github. I've submitted this issue for you.
I am not 100% sure if what OP meant is just to refer to the indentation in the editor (namely, VSC) or if, by this:
i.e. the string ends up indented, which seems what you almost never want - why have an arbitrary amount of white space on the next line of this string?
...they also meant to refer to the actual output of the multi-line string,
(or also, just in case anybody else finds this post looking for a way to avoid this affecting the actual output of the multi-line string), I'd like to add as a complementary answer (cannot comment yet) that this was already beautifully answered here.
If that's the case and you're reading this for that reason, in short, all you want is to import the standard lib 'inspect' and post-process your string with it, using the cleandoc method.
Without breaking the indentation in your IDE, this method makes sure to give you the string output you actually expected:
All leading whitespace is removed from the first line. Any leading whitespace that can be uniformly removed from the second line onwards is removed. Empty lines at the beginning and end are subsequently removed. Also, all tabs are expanded to spaces.
(From the docs link above)
Hope that helps anyone.
As part of a piece of python work I have to ask for a first name and surname, then repeat it three times if it is correct. When I try it Python puts a syntax error on the colon. What do I need to do to correct it?
Basically whats going on
I've already tried removing the colon, bringing the if line down to one equals, and looking for bracket errors, but I cant find anything.
The colon should be at the end,
if input == yes:
However I cannot see how this can work? Is that the full code? If so, what is the yes variable?
If it was intended to be a string, the line should be,
if input == "yes":
The "" tells Python that it is a string (a word).
A link to Python syntax: https://en.wikipedia.org/wiki/Python_syntax_and_semantics
it my first time using Stack Overflow so please excuse any mistakes i have made. Im creating a program and i want ask mathematical questions for the user. But my program will generate two random numbers, and a random arithmetic operator will occur. They are plus, minus and times. So i put them into an array and this is the code.
Code:
The Error i gained:
It said the Error is in Line 10.
Ive tried doing this 'What is'+str(Ran) +,+str(op) +,+str(dom) +'?')
However i gained an invalid syntax on the comma.
Ive tried searching for this particular program, but all of them seem to have something called classes and def in. If it is possible, can i please not use the def and class in my program because i am new to python and i still need to learn what they are.
I am using Python 3.4.2, on a Windows 8 operating system if you wanted to know.
Thanks for reading, i am looking forward to have any assistance in my problem.
+ + is invalid syntax. You should be doing str(something) + ' ' + string(something_else) if you want to add two strings with a space in between. You also need quotes around add, minus and times in the list in order to make them strings.
got a bit of a noob question.
I'm trying to get Metagoofil working because it keeps saying "error downloading webpage" etc etc.
A google search found that I can change a bit of the code in one of the config files and it will work properly again.
I'm having a problem though: this seems to be the code I want to use.
self.url = url.replace("/url?q=", "", 1).split("&")[0]
BUT, it doesn't seem to like me (based on syntax highlighting) have those two quotation marks together with nothing in between. When they are like above, it starts highlighting .split(" up to here thinking that this is the string.
My question is, how can I make the double quotations together without anything in the middle and have it register as its own string, so it doesn't highlight the .split("
The literal "" is a valid string with a length of zero. I guess your syntax highlighter is not working properly.
I've scanned the questions here as well as the web and haven't found my answer, this is my first question and I'm a noobie to (wx)Python so go easy on me.
Using TextCtrl I'm trying to remove a single character within a string, this string will always start with the same set of characters but the rest of the string is freely editable by the user.
e.g
self.text=wx.TextCtrl(panel,-1"hello world,, today we're asking a question on stackoverflow, what would you ask?")
poor example but how would I find and remove the 11th(',') character so the sentence is more formatted without affecting the rest of the string?
I've tried standard python indexing but I get an error for that, I can successfully remove chunks of the string from the start outwards of the end inwards but I need only a single character removed.
Again, sorry for the poor terminology, as I said I'm fairly new to python so some of my terms may be a bit iffy.
self.text.SetValue(self.text.GetValue()[:10] + self.text.GetValue()[11:] )
maybe??
self.text.SetValue(self.text.GetValue().replace(",,",",")
maybe?
its not really clear what you are trying to accomplish here ...