Starting from:

$25

CS5007-HomeWork 1 Solved

HomeWork 1 - CS5007

1             Arithmetic expressions 
Convert each of the following mathematical expression in an equivalent Python expression. Write the expression in the designated space in your template module a line of Python code.

The values of the three rational variables a, b and c are assigned at the beginning of the template module and should not be modified.

a.                    4ab + bc

b.                    b3

√ 

c.                     ab

d.                    (ac + ba)/bc

e.                    a2 − b4 + 2ab

2             Expressions, Python operators 
Write the following Python expressions into the designated places in the template module. Run the module.

a.               (8//6) ∗ 6

b.              (8/6) ∗ 6

Explain in a comment line why the value of expressions a. and b. are different.

3             Boolean expressions 
Convert each of the following logical expression in an equivalent Python expression.

Write the expression in the designated space in your template module a line of Python code.

The values of the Boolean variables a, b and c are assigned at the beginning of the template module and should not be modified. Recall that ∨ is “or”, ∧ is “and”, ¬ is “not” and → is implication.

a.               a ∧ (b ∨ c)

b.              a → (b ∨ c)

c.               (a ∧ b) ∨ (¬c)

d.              a → (b → (¬c))

4             Function 
Wind chill is defined by the following formula:

Wind Chill = 13.13 + 0.621 × T − 12.1 × V 0.15 + 0.3967 × T × V 0.16

In this formula, T is the temperature in Celsius and V is the wind velocity in kilometers per hour.

1)                Define a function WindChill in your template module to calculate the wind chill for any temperature and velocity. For instance, a call to WindChill(−20,30) prints the following result:

At -20C and 30 kph winds, it feels like -33.1156286189848C

Your function should NOT return anything, but PRINT the result on IDLE. Call your windChill function with arguments -20 for T and 30 for V.

2)                Write a similar function, named WindChill2, that does not print but returns the result. Write an appropriate statement using this second function, so as to print this returned result.

5             Errors in a Python program 
def euc(x1,y1,x2,y1): lambda = (x1-x2)**2 gamma = (y1-y2)**2

return((lambda+gamma)**(1//2)) result = euc(1,3,2,7) print("result")

Function euc was written to calculate a distance with following formula:

 p((x1 − x2)2 + (y1 − y2)2

Unfortunately, the function definition, call and print statement contain 5 errors. Explain in a command line each error, within the template module. Re-write correctly the function and the call/print statement in the template module.

More products