Monday, 9 June 2014

Maths

Lesson Aims:

To be able to perform basic calculations using python.

Introduction

In python the first role of the computer was to be able to crunch numbers quickly - very quickly.

There are a number of mathematical operators that are built into python.

Reference - https://docs.python.org/2/library/stdtypes.html#numeric-types-int-float-long-complex.  The imprtant types here for you to know are int (a number without a decimal part), and float (a number with a floating point.  Ignore complex numbers - they are something you will do if you study A' level Mathematics.  and long numbers are just as their name suggests - long. 

Task 1

Code 1
  • Create a new file called numbers.py, put the code above in it.
  • Explain what each line does in your own words.
  • What are the variables used in this program?


Task 2

There are also some more advanced mathematical functions available in a module called math.  To use the math module you need to import it first.

Code 2
Create a new file called numbers2.py
Enter the code above and run it.

  • What does the import statement do?
  • What does the octothorpe in line 4 do? (Octothorpe is the correct word for the symbol # also known as the number symbol, pound symbol, or more recently as a hash-tag)
  • What variables are used in this program - what do they each do?

Task 3

Write a program which will ask a user to enter the short two sides of a right-angled triangle and calculate the length of the long side.

Hand in

Hand in, via moodle, a word document with:
  • A link to your github repository
  • Answers to the above questions.

Remember 

To push back from c9.io
  • git status
    • Tell you the status of your repository
  • git add .
    • Adds new files to the tracker
  • git commit -a -m"put a message here"
    • Commits the changes you have made, with your message - short note about what you have done.
  • git push origin master
    • pushes the comitted changes back to the origin (where it came from - github) on the master branch. (yes you can have more branches - but dont worry about that yet.)



No comments:

Post a Comment