Practice 2 (Year 2 Sem 1)

Practice 2 is the second practice in semester 1 of year 2, and the second practice in the total of year 2. It is a practice for selection, and is considered to be easy.

Description
No description was provided for this practice.

Unlocked after completion

 * Practice makes perfect! (Score at least 60% for Practice 2 [Chapter 4])
 * Intern of the Year (Score at least 60% for Practice 2 [Chapter 4])
 * Challenge 2: Selection (Complete Practice 2 [Chapter 4])

Question
is a function which will help calculate your bmi and classify the category based on the input height (in metres) and weight (in kilograms). It will take in an input height and weight, updates the variable  accordingly and returns it.

BMI = (Weight in Kilograms / (Height in Meters x Height in Meters))

BMI Categories: Complete the code required.
 * Underweight = <18.5
 * Normal weight = 18.5–24.9
 * Overweight = 25–29.9
 * Obesity = BMI of 30 or greater

Solution
Make sure that your code does not run code not belonging to the conditions passed in to the function. One way to do this is to check for both lower than the higher limit and higher than the lower limit.

Question
is a function which will help classify your diploma type based on the input CAP score. It will take in an input CAP, updates the variable  accordingly and returns it.

The CAP is classified as follows: Complete the code required.
 * High Distinction (CAP >= 4.5)
 * Distinction (CAP >= 4.0)
 * Merit (CAP >= 3.5)
 * Graduation (CAP >= 2.5)
 * Others (<2.5)

Solution
Similar to the above question.

Question
is a function which take in 4 points and check if the two lines denoted by the points will intersect. It will take in (x1, y1) and (x2, y2) which denotes line 1, and (x3, y3) and (x4, y4) which denotes line 2. It then checks if the two lines will intersect, updates the variable  accordingly and returns it.

For example:

Line 1 with (2, 2) and (7, 6), Line 2 with (4, 2) and (-1, -2) are parallel with each other, hence willIntersect = False

Complete the code required.

Solution
You only need to check if the gradients are similar or not, it does not matter if the 2 lines denoted by the points do not intersect even with different gradient.

You might need to check for the corner case if x1==x2 or x3==x4, then the gradient is undefined.

If both gradients are undefined, the lines intersect.

Question
is a function which takes in a three-digit integer and determines whether it is a palindrome number. It will update the variable  with True or False, and returns it.

A number is a palindrome if it reads the same from right to left and from left to right.

You may assume the input number will be a 3-digit number.

For example,

121 is a palindrome, so isPalindrome = True

123 is not a palindrome, so isPalindrome = False

Complete the code required.

Solution
Convert the number into a string, then check if the first character and the last character are equal with str[0] and str[-1].

Alternatively: use number//100 for the first digit and number%10 for the last.