If you are using Linux or Mac with Python 3 you may need to type python3 user_input.py. Open the Terminal tab in the bottom and type python user_input.py. Let's run it manually in the terminal to demonstrate. The user input is green and italicised in the P圜harm console, but it would not normally have any special colors in a regular terminal. When we enter our name it is on the same line as our prompt. Add a space at the end so there is room between our question mark and where the user types in their name. Remove the print statement and put a text string inside the parenthesis for the input function. When we pass the input function a string as a parameter it will display the string as a prompt to the user and wait for their input on the same line. Input actually takes a parameter just like the print function. ![]() Well, that's better, but it would be even nicer if the user entered their name on the same line as the prompt asking for their name. We should print a message saying Please enter yourname. Someone running this program wouldn't know what to do. Now it looks like the program has exited as we see the exit code with a note that process has finished.Īlso notice how the icons in the left change when a program is running versus not running. The python interpreter is waiting for our input before moving on to the next line of code (or in this case, ending the excution of the program) What's happening? Notice we don't see the exit status, so the program has not finished running yet. On a new line in the same file type type input() There is another function built-in to Python called input(). In the editor, let's start the program by greeting the user. In P圜harm, right click the root project folder in the project panel and select New Python File. In this lesson we will learn how to get input from the user and other ways of getting input and output from a program. We wrote a hello world program last time that simply prints out some text, and learned how to commit files to our git repository and push the changes over to GitHub. The previous videos explain what the cookbook method is and how to get yours started. ![]() Hello this is NanoDano at with the next video in the Python Cookbook series. ![]() View the full playlist on YouTube: Learn Python - Build a Cookbook Transcript
0 Comments
Leave a Reply. |