Input and Output Python 3 Beginner 3 Input
Input and Output Python 3 Beginner #3
Input and Output? • input() • print() • Lets make output look nice!
Joining strings • Python allows us to add strings together with the + symbol • Create a variable called: name = “draps” • Then lets format our output a little: • print(“Hello, my name is “ + name) • The part in quotes is a hard coded string. • More dynamic code. • Alternatively print(“Hello, my name is“, name)
input() function • input() • name = input("Please enter your name: ") • input() gets a string from the user.
Python files • To get the true python coding experience we need to start writing instructions into a file. • . py for Python! • Create a file called tut 3. py in your favorite text editor, I’ll use vim. • Lets add some instructions similar to the ones we wrote just before.
Running. py files • On linux, from the terminal you can execute a python script in the current directory by using the command: • python 3 tut 3. py • On Windows, right click the file and open with IDLE, then hit the run tab up the top and select “Run Module”
Multiply Program • • Lets make something a little more useful Lets edit tut 3. py We will get two numbers from the user Times them together and output the answer to the console.
Next • Selection! • Feel Free to leave questions in the comments I’ll try to answer all of them. • Please Google your question first!
- Slides: 8