Python Introductory TutorialWhat is Python?Using the Interactive Python InterpreterQuestionsCS 110: Introduction to Computer Science Spring 2008Python Introductory TutorialWhat is Python?Python is a relatively new language that is great for beginning programmers and a language used in many real-world projects aswell. The following are its key ingredients:- An interactive interpreter- Relaxed typing- Structured or Object-oriented programming- Lots of cool libraries - Simple syntaxo Allows beginning students to focus on problem solvingo Create cool programs early onUsing the Interactive Python Interpreter1. Login to Linux with your user name and password.2. Open a term window by selecting System | Terminal.3. Enter "python" at the prompt. This will start the Python interactive interpreter. With the interpreter, you can try individualpython commands and quickly learn the syntax of the language.4. When you enter 'python' you should see the python prompt >>>. This is asking you to enter python commands. Type in the following to see what happens:print 'hello'.print 3*6print 3/6print 3.0/6.0print 2+4*2money=324.56interestRate=0.1oneYearReturn=money*interestRateprint oneYearReturnprint 'abc'+'def'first='david'Python Introductory TutorialCS 110: Introduction to Computer Science Spring 2008last='wolber'print first+' '+lastx = 5print x*7print 'x'*7type (x)type ('x')type (3)type (3.4)type ( ['a','b','c'] )list =['a','b','c']list[1]list[2]=44listresult=pow(4,3)print resultQuestions1. Why does 3/6=02. What is a ‘variable’? What variables are in the sample?3. What is the value of 2+4*2? Why?4. Python lets you add strings, e.g., 'abc'+'xyz'. What does '+' do?5. What is the result of 'x'*76. What does the 'type' command do? What is a type?7. What types did the sample list?8. What was printed out for the final line, ‘print result’? What do you think ‘pow’ stands for?Writing a Program in a FileThe interactive interpreter you just used is for trying small commands out and learning Python. When you write programs, you won’t use the interactive interpreter. Instead, you’ll create programs in files and run the whole thing at once. To do so, open a WYSIWYG editor (ask your professor if you can’t find one). Then perform the steps on the following page.Python Introductory TutorialCS 110: Introduction to Computer Science Spring 20081. Create a new file and enter the following statements:print "hello"print "world"name = "jive"print name2. Save the file as hello.py3. Back at the terminal window, enter: python hello.pyThe following should be printed on your screen:helloworldjivePython Introductory
View Full Document