I would suggest you post a minimal reproducible example of your failing code or delete your question and instead post the query to a more appropriate site, perhaps Super User — Compo.
It's not an exact duplicate, but the relevant lines of code are identical: stackoverflow. Add a comment. Active Oldest Votes. Improve this answer. Mofi Mofi Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Making Agile work for data science.
Stack Gives Back Now, type in the following code:. This is a basic program that takes input from the user and checks if the inputted number is an even number or not. Our python program is ready to go!!!
Now all we need is a batch file. They basically let you run multiple commands by just running the batch file. Creating a batch file is easy! We can create a batch file using notepad just like we created our python file.
Type in the following commands:. Remember the python file we created in the first step? Maybe you can change it to "x" or "y" or something simpler later on, but for now, keep it as grapes.
This whole line creates a sort of question, which you need to type something in and press enter to continue. Whatever you type in is the data stored in the variable.
That means, if you type in "yes", that would mean that the variable grapes is equal to "yes". Oh yeah, and don't forget the equal sign. Now on to line 5.
Pretty simple, except for the last part. That's because, ladies and gentlemen, putting a variable in between two percent signs basically puts the data there. If you typed in "yes" for the fourth line, it would say "You said: yes". That's alot of learning. It might be hard to understand this, but it's a whole different story to make this. I'm sorry, I'm doing the best I can :. You have made it this far in the tutorial! You are awesome! If you didn't make it this far, you stink.
But since they didn't make it this far, they wouldn't see this message, therefore it's okay to say. We learned in the last step how to create a question I guess that's what you call it in batch code. Now we have to make the computer do something.
Forex, if you asked someone "What's two plus two? Now how would we make that in batch file code? Basically, it will go like this: The question is asked "What is two plus two? If the user types in 4, say "Correct! If the user says anything else, say "Incorrect! Now, let's make that in code. Before you bulge your eyes out, let me try to explain. Hopefully you understand lines A brief refresher on 4, whatever the user types in, is basically stored in the variable "answer".
Line 5 Here's where it get's tricky. This is because the single equal sign is used for many other purposes. That's what it's saying. Now in the parentheses, you understand the "echo Correct! But exit? It was so simple, I forgot to explain. Basically, this will just exit out of Cmd as a whole. This is saying if the answer is not 4, then do whatever is in the parentheses. TIP: Always remember, when doing else statements, put a space between the "else" and the opening parentheses.
The first one is fine. I made a batch game wth some code like u, but when i opened the file, it open and suddenly dissapear in 1 second. Wht is that error? Reply 16 days ago. Question 7 months ago. Why is there an issue? Tip 11 months ago. You can delete and start files from a batch file, so be careful are you put in there. I made an Explorer Restarer. Since learning about batch files, I started to make viruses and test them myself.
It was so fun. But I wanted to learn more, and with your article, I got even better at making batch scripts. Feel free to ask me any questions. I know this was worded weirdly, but I assure you this was the best I could do. I have a problem explaining things, and I'm much better at showing things visually.
0コメント