60 likes | 235 Views
Python Lab #1. 1. Intro to Python. Adriane Huber Debbie Bartlett. Python Lab #1. 2. Python. Named derived from TV series, Monty Python’s Flying Circus, not the snake Important goal of developers was to make it fun Common practice was to make Monty Python references in example code
E N D
Python Lab #1 1 Intro to Python Adriane Huber Debbie Bartlett
Python Lab #1 2 Python • Named derived from TV series, Monty Python’s Flying Circus, not the snake • Important goal of developers was to make it fun • Common practice was to make Monty Python references in example code • Created by Guido Van Rossum in 1991 • Python is often compared to Tcl, Perl, Ruby, Scheme or Java • Why use Python? • General-purpose, interpreted high-level programming language • Design philosophy emphasizes code readability • Supports multiple programming paradigms • object-oriented and to a lesser extent functional • Can be used in a scripting or non-scripting context
Python Lab #1 3 Sample Python Script def greet (): print (“Hello, World!”) name = input (“Enter your name:”) if name == “Debbie”: print (“Hello, Debbie! I am glad that you are in CS192 today!”) else: print (“Hello”, name) greet()
Python Lab #1 4 Python Scripts • Creating a Python Script • Use a text editor such as gedit • Name the file greet.py • Write your script in greet.py • Save greet.py • To run python program in terminal window, type: • Python3.3 greet.py
Python Lab #1 5 Python Lab1 Assignment • Type your own version of the python script • What happens if you • don’t use quotes around the first print statement? • Take them off, try it, then put them back • delete the tab in front of the first print statement? • Try it, put it back • remove the colon at the end of the first statement that begins with def? • Try it, put it back • Ask another question in your script • Google a “while loop” • Add a while loop to your Python Script • Show your script to a lab instructor or helper