This question already has answers here:
How do I do a case-insensitive string comparison?
(15 answers)
Closed 7 months ago.
I’m new with Python. Just One question.
I try to create a mini quizz game and i want avoid this :
Answer = Input(« « « Who sing : « Thriller » ? » » »)
If answer == « Michael Jackson »:
Print(« Good. »)
Else:
Print(« Wrong. »)
The problem is that if the user answer «michael jackson », the code run with wrong.
How can i fixed that?
Thanks
The way that this is usually done is to just turn all the input to lowercase. This can be done with the .lower() method on the input string. The corrector answer would then be "michael jackson".
Related
This question already has answers here:
how to detect and get url on string javascript [duplicate]
(2 answers)
Closed 1 year ago.
I have been looking for a way to parse URL from a string.
My current goal is to parse
https://example.com/foo.png
from a string like
abcxyz https://example.com/foo.png gibberfish text.
Anyone got a solution or a package that can help me to do the job?
Thanks in advance.
text = "abcxyz https://example.com/foo.png gibberfish text."
console.log(text.split(" ")[1])
.split() splits the string at spaces into an array of words.
You can refer: https://www.w3schools.com/jsref/jsref_split.asp
I recommend this solution. It turns all words into an array and picks out the ones starting with https://
text.split(" ").filter(i => i.startsWith("https://")).toString();
This question already has answers here:
How to use string.replace() in python 3.x
(9 answers)
Closed 5 years ago.
I am trying to write a program that replaces every 'a' for '&'.I am currently stumped and was wondering if someone could write it for me to get an idea of what it would look like. Thanks.
strw = "kabhi kabhi mery dil main khyaal aata hy"
print (strw.replace("a", "&"))
This question already has an answer here:
How to convert a jQuery filter for use with waitForKeyElements?
(1 answer)
Closed 7 years ago.
So far i have this code:
$('.js-stream-item:has(span.ProfileTweet-action--retweet:has(span.ProfileTweet-actionCount[data-tweet-stat-count="0"]))').toggle();
It works fine but only remove tweets with 0 retweets, how can i use the attribute "data-tweet-stat-count" by condition ?
Thanks in advance.
I think you could do something like this:
$('div.stream-item-footer:has(span.action-retweet:has(span.actionCount))').filter(function() {
return parseInt($(this).find('span.actionCount').attr('data-tweet-stat-count')) >= 3;
}).toggle();
This question already has answers here:
Split string in Lua?
(18 answers)
Closed 9 years ago.
I have one string, that is = s = "Pedro Martinez, Defense"
I want to split the string before the comma and after the comma, store those cuts on 2 variables, for example:
I think that I need to use the string.gmatch function or string.sub
How can I do that?
The accepted answer at How to convert GPS coordinates to decimal in Lua? shows how to use string.match and patterns. Applying the same techniques as mentioned there, you could use
local name, expertise = string.match(s, "(.*),%s*(%a*)")
which would lead to name being "Pedro Martinez" and expertise being "Defense".
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
What is the difference between String.Empty and “”
What is the difference between code and where it is applicable??
string mystr = "";
string mystr1 = String.Empty();
The answer appears to be 'nothing'.
However, good programming practice says that you should preferably use string.Empty, as if in the future an empty string were to be represented by something other than "", your code otherwise might break. (I can't see tha change happening, but in principle it might).
I think this will explain it for you: http://msdn.microsoft.com/en-us/library/system.string.empty.aspx