Beginner Python problem with if statement - python-3.7

Apologies in advance because this is probably fairly stupid.
Basically I was just messing around trying to figure out how to work with inputs (I'm pretty new to coding) and I came across an issue within an if statement.
x=input("What is your name? ")
name=x
print("Hello,", name, "nice to meet you")
y=input("Would you like me to close now? (yes/no) ")
listx=["no","No","NO","nO"]
for response in listx:
if response == y:
input("Why? ")
input("I think you're being rather terse", name, ". ")
input("No, you. ")
input("So that's how it's going to be? ")
input("Well I'm closing anyway. ")
input("Bye then. ")
I kind of just thought it would take me through this funny little exchange and over time I could customise the responses but there's a problem at this point:
input("I think you're being rather terse", name, ". ")
At this juncture the code doesn't seem to recognise name; I defined name because it wasn't working when I just used x either. I'm assuming that the code doesn't recognise it because the if statement is essentially within a vacuum or something but how exactly would I work around this? I want to be able to call back details which happened previously within the conversation to try to make it funnier.

You can't do that with input() statements - it only works with print(). So print() can take any number of strings as an argument, but input() will only take one (and in recent versions of python will raise an error if you try to give it more than one - when I tried to run your code myself, I got a TypeError).
If you want to include name in the text of the input(), you'll need to either concatenate it:
input("I think you're being rather terse " + name + ". ")
or use a format string to insert it:
input(f"I think you're being rather terse {name}. ")

Related

Autohotkey / AHK - String as function parameter without " "

Is there any way to define function parameter as string by default, so I could send them without using double quotes?
If you know C++ and want to compile your own version of AHK from the source code, or if you want to make an other script which will insert in the quotes automatically after the fact, then yes. Otherwise no.
And I really don't know why you'd want to do this. Seems terrible in my opinion.
Maybe you're used to legacy AHK? If so, you really should let go of that. Maybe about 10 years ago it was fine to use.

PHP upgrade from 4 to 5 requires changing ereg_replace() and ereg() with delimiters

When running former PHP 4 pages in PHP5 I get Deprectiated errors:
I know there are some back slashes that go in there. (or is it forward slashes?) but the " +" item to replace throws me off.
Function ereg_replace() is deprecated:
$perms = ereg_replace(" +", "&", #trim($tmp[0]));
Now this one below really has my mind bent. Only after wearing out my keyboard G-O-O-G-L-E keys did I take a chance and just paste in some code. I decided to answer this question with the hopes of helping someone as challenged as me. What the heck is a "callback function"? I know, I probably use this stuff all day long in other programming languages. Oh well. I think my anxiety level overclowded my correct selection of a forum to answer my simple beginner questions.
preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead:
$string = preg_replace("/&#([0-9]+)/e","chr('\\1')",$string);
My confusion in other StackOverKnow threads and answers is examples are too elaborate. I think someone (including me) could benefit from someone simply typing in the example fixed in correct sytax. I just don't live around this subject that much and because of the millions of lines of code in this RTF generator I'm having to upgrade I'm scared of the "sprong!" effect: I change something and cascading problems occur and I can never change it back.
We purchased a nifty RTF Generator for our club to generate a Word document from our PHP list of hikes. This is where I am finding the Depreciated errors. Just sayin', someday you might need a Word document created from PHP. Hard to find this stuff and it has worked well for the last 9 years.
The " +" is confusing because double quotes and plus sign made me think it was part of the function, not the input.
$perms = ereg_replace(" +", "&", #trim($tmp[0]));
answer: preg_replace("/ +/", "&", #trim($tmp[0]));
This one had me scratching my head about "what function? there is no function!" until I found this almost obscure example and picked the middle solution:
preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead:
$string = preg_replace("/&#([0-9]+)/e","chr('\\1')",$string);
$string = preg_replace_callback("/&#([0-9]+)/", create_function ('$matches', 'return chr($matches[1]);'),$string);
I found This link with comparsions between Depreciated and Replacement to be very useful.

How to understand this perl multi-line writing command

I am trying to understand the perl commands below:
$my = << EOU;
This is an example.
Example too.
EOU
What is the name of this way? Could somebody can explain more about this "multi-line writing" command?
Essentially the syntax is allowing you to put anything unique as a marker so that it won't conflict with your contents. You can do this:
$my = <<ABCDEFG;
This is an example.
Example too.
BLAH
ABCDEFG
Everything between "This.." and "BLAH" will be assigned to the variable. Note that you shouldn't have a space after the << symbols otherwise you will get a syntax error. It helps avoid adding CR characters, or append (.) everywhere, and useful when passing data into another application (eg. ftp session). Here Documents is the correct term for this.
Everything between <<EOU and EOU is a multi-line, non-escapable, string. It's nothing fancy, think of them as start and end quote marks with nothing inside requiring escapes to be literally what you typed...

String trigger IRC script

I need a script for IRC client (using KVirc) that will play a sound located somewhere on my hard drive whenever a certain piece of string is mentioned on the main channel. I assume such a thing is possible, but after some time of learning about scripting, I haven't found a way to do this on my own, and would be very grateful to anyone who would either write the piece of code or guide me how to do it myself.
Just a side note, this certain string I have in mind is not an exact string where all the characters are defined, but just first few letters, I assume the $ character is a substitute for all the text after the defined string.
Here it is, I hope I'm not too late xD
Open up KVIrc, hold ALT and press ENTER, it will bring up small console.
In there just copy this:
/event(OnChannelMessage,sounds) { %match_string = "abccc";
%music_file = "C:\\YouTubeMp3\\Selo\ Gori\\CĂ©line\ Dion\ -\ My\ Heart\ Will\ Go\ On-WNIPqafd4As.flv";
if($str.match(%match_string*,$3)) snd.play %music_file;
}
Of course, you should change %match_string and %music_file path, if you have spaces in path just escape them with backslash (), just like I did it.
If you have any questions or you need something else for KVIrc feel free to contact me on Rizon IRC network, nickname is DonVitoCorleone.

What's so great about Block Selection Mode?

Longtime Eclipse user here; I recently discovered the "Block Selection Mode" (Alt-Shift-A) that was added into Eclipse 3.5. I tried it out, it's pretty neat--I can select a rectangle of text in my source code instead of selecting things a line at a time like I usually do.
Apparently this feature is common in other editors too, under other names like "column edit mode", etc. A lot of people seem to really love it, but I've got by without for a long time.
So my question is: What kinds of things is this feature useful for?
The only one I can think of is inserting a comment characters (like // or #) in front of a chunk of text. Also, I supposed if I had a bunch of variables names that were all lined up and I wanted to change the first characters for all of them at once. But surely there's more to it than that? I mean, when it comes to choosing an editor, this feature is apparently a deal-breaker for some people!
I find it is very useful when working with fixed-position field data files, and you only want to select a few fields for search-replace or copy-paste. It is also good for things like this:
call_foo('A',123);
call_foo('B',143);
call_foo('C',331);
call_foo('A',113);
call_foo('R',789);
The code is all the same except for some characters in some columns. You could select a block around the second parameter and search for the line containing 113. Useful when you have more than just a few lines all together in this format.
A colleague of mine told me of a project where they wrote JDBC code like this:
String query =
"select question, answer, accepted " +
"from so_answers " +
"where poster = 'Jon Skeet' " +
"order by upvotes ";
So that they could block-select the SQL in order to paste it into a database tool and run it by hand. Seems a bit barmy to me, but it evidently worked for them.
If you arn't using a block cut/copy/paste operation at least four or five times a day then I would suggest you're just doing a lot of extra typing.
If you are looking at a file with fixed width fields, sometimes you only want to select one column.