Exercises

Welcome to Python! Once you have properly installed Python and WingWare 101, when you launch WingWare, you should see the project explorer, the editor and the output window:

The Python Workshop website has all the links you will need throughout this workshop as well as many others which you will find helpful as you begin to get more proficient in Python. You may ask, why did we decide to do this in Python? 

Well, Python

  • Gives you a chance to experiment with the language in an interactive setting with immediate feedback
  • The syntax is not too complicated
  • The language is simple yet powerful
  • Is easy to install and get started
  • free Load the WingWare environment and do the following exercises:

Exercise 1: Directly at Python prompt Note that you can enter expressions for evaluation directly at the Python prompt. Try the following:

  • 2 + 3
  • 26/3
  • 5 % 2
  • 5 * 3
  • 1 + (3-2)

Are you convinced that Python obeys the usual arithmetic evaluation rules. Enter some more expressions of your own to convince yourself.

Exercise 2: String Expressions At the prompt, we can also enter string expressions. Try the following:

  • Hello
  • ‘Hello’
  • “Hello”
  • “Hello” + “World”

Exercise 3: Print We can also use the command “print” to print out the results as in the following:

  • >>> print “Hello, world!”
  • >>> print “Robert” + “ “ + “Geofroy”
  • >>> print “Robert” + “Geofroy'
  • >>> print
  • >>> print 24/3
  • >>> print 25/3
  • >>> print 26/3
  • >>> print 27/3
  • >>> print 24/3.0
  • >>> print 25/3.0
  • >>> print 26/3.0
  • >>> print 27/3.0
  • >>> print 35+22
  • >>> print 35-22
  • >>> print 35*2
  • >>> print 2**2
  • >>> print 3**2
  • >>> print “Py” + “thon”
  • >>> print “Py” + 2
  • >>> print 13%5
  • >>> print 14%5
  • >>> print 1 + 4j

Exercise 4: Casting We can change a data type easily as follows:

  • >>> print int (12.3)
  • >>> print int (12.4)
  • >>> print int (12.5)
  • >>> print int (12.6)
  • >>> print int (12.7)
  • >>> print int (12.8)
  • >>> print float (4) + 5

Exercise 5: Variables We can define variables and then use these in further expression evaluation:

  • >>> planet=”Pluto”
  • >>> moon =”Charon”
  • >>> p = planet
  • >>> print p