Skip to content

Higher Diploma in Science in Computing (Data Analytics) - Programme Module: Programming and Scripting (COMP08049)

Notifications You must be signed in to change notification settings

Munster2020/HDIP_CSDA

Repository files navigation

Higher Diploma in Science in Computing (Data Analytics)

Programming and Scripting (COMP08049)

Topic 2: Statements

For this topic I had to write a program that calculates somebody's Body Mass Index (BMI). The inputs are the person's height in centimetres and weight in kilograms. The output is their weight divided by their height in metres squared.

Program & Sample Data

  • $ python bmi.py
  • Enter weight: 65
  • Enter height: 180
  • BMI is 20.06.

Topic 3: State

Fot this task I had to write a program that takes asks a user to input a string and outputs every second letter in reverse order.

Program & Sample Data

  • $ python secondstring.py
  • Please enter a sentence: The quick brown fox jumps over the lazy dog.
  • .o zletrv pu o wr cu h

Topic 4: Controlling the flow

In this weeks task I had to write a program that asks the user to input any positive integer and outputs the successive values of the following calculation. At each step calculate the next value by taking the current value and, if it is even, divide it by two, but if it is odd, multiply it by three and add one. Have the program end if the current value is one.

Program & Sample Data

  • $ python collatz.py
  • Please enter a positive integer: 10
  • 10 5 16 8 4 2 1

Sources

Topic 5: Data

I week 5 we looked at data and had to write a program that outputs whether or not today is a weekday. An example of running this program on a Thursday is given below.

Program & Sample Data

  • $ python weekday.py
  • Yes, unfortunately today is a weekday.

An example of running it on a Saturday is as follows.

Program & Sample Data

  • $ python weekday.py
  • It is the weekend, yay!

Sources

Topic 6: Functions

This week I had to write program that takes a positive floating-point number as input and outputs an approximation of its square root. You should create a function called sqrt that does this.

Program & Sample Data

  • $ python squareroot.py
  • Please enter a positive number: 14.5
  • The square root of 14.5 is approx. 3.8.

Sources

Topic 7: Files

For this weeks task I had to write program that reads in a text file and outputs the number of e's it contains. The program should take the filename from an argument on the command line.

Program & Sample Data

  • $ python es.py moby-dick.txt
  • 116960

Sources

Topic 8: Looking ahead - matplotlib

In week 8 we had to write a program that displays a plot of the functions f(x)=x, g(x)=x2 and h(x)=x3 in the range [0, 4] on the one set of axes.

Sources

About

Higher Diploma in Science in Computing (Data Analytics) - Programme Module: Programming and Scripting (COMP08049)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages