Difference between revisions of "More to Python"

From CompSciWiki
Jump to: navigation, search
m (Added comic credit)
 
(19 intermediate revisions by 5 users not shown)
Line 2: Line 2:
 
|Chapter_TOC=[[Extra Labs]]
 
|Chapter_TOC=[[Extra Labs]]
 
|Previous=[[Introduction to Python]]
 
|Previous=[[Introduction to Python]]
|Introduction=More to Python
+
|Introduction=In the previous lab [[Introduction_to_Python|Introduction-to-Python]] you were taught what the Python programming language is and some basic features of Python.  In this lab we will go a little more in depth in regards to what other things we can do with Python. Furthermore, you will learn how to use Strings, Data structures (arrays, lists, tuples) and functions(Methods in Java) in Python.
 +
 
 +
[[Image:More_on_Python.png|800px|Image by Graeme Peters]]
 +
 
 
|Body=
 
|Body=
 
==String Method==
 
==String Method==
Your task is to ...
+
===[[Count the Vowel]]===
 
+
==Data Structure==
First, we need three variables:
+
===[[Create an Array]]===
#input - hold the user's input
+
===[[Print an Array]]===
#vowelCount - keep track of vowels
+
==Functions==
#done - control the while loop
+
===[[Add Area]]===
 
+
===[[PrintArray Function]]===
Second, we need to get the user's input using raw_input(prompt)
+
{{CodeBlock
+
|Code=
+
#get the user's input
+
input = raw_input("Enter a sentence:")
+
 
+
 
}}
 
}}
}}
 
 
 
Then we'll check the vowelCount
 
{{CodeBlock
 
|code=
 
input = input.toLowerCase();
 
}}
 
 
==Create an Array==
 

Latest revision as of 17:34, 5 April 2012

COMP 1010 Home > Back to Extra Labs

Introduction

In the previous lab Introduction-to-Python you were taught what the Python programming language is and some basic features of Python. In this lab we will go a little more in depth in regards to what other things we can do with Python. Furthermore, you will learn how to use Strings, Data structures (arrays, lists, tuples) and functions(Methods in Java) in Python.

Image by Graeme Peters

String Method

Count the Vowel

Data Structure

Create an Array

Print an Array

Functions

Add Area

PrintArray Function