Python question Application: Python Fragment Formulation (Q1 – Q4) In this group of questions you are asked to produce short pieces of Python code. When you are asked to "write a Python expression" to complete a task, you can either give the expression in one line or break down the task into several lines. The last expression you write must represent the required task. Question 1 (Reduce parentheses) Give an equivalent version of this expression by removing as many redundant parentheses as possible, without expanding the brackets or simplifying. (x**(2**y))+(y*((z+x)**3)) Question 2 (Translate arithmetic concept into Python) You are given a list of numbers, named numbers, containing 3 integers. Write a python expression (one line) that evaluates to True if and only if the product of any two numbers in the given list is greater than the sum of all three numbers. Note: the product of two numbers, x and y is x*y. Question 3 (List/table access) You are given a table, car_count, which has three columns, day (string), hour (integer in 24 hour format) and number of cars (positive integer), that contain the count of cars that pass through an intersection. For example: car_count = [['Monday',0,0],['Monday',1,0], ...,['Wednesday',13,7],...]
Max Function
Statistical function is of many categories. One of them is a MAX function. The MAX function returns the largest value from the list of arguments passed to it. MAX function always ignores the empty cells when performing the calculation.
Power Function
A power function is a type of single-term function. Its definition states that it is a variable containing a base value raised to a constant value acting as an exponent. This variable may also have a coefficient. For instance, the area of a circle can be given as:
Python question
Application: Python Fragment Formulation (Q1 – Q4)
In this group of questions you are asked to produce short pieces of Python code. When you are asked to "write a Python expression" to complete a task, you can either give the expression in one line or break down the task into several lines. The last expression you write must represent the required task.
Question 1 (Reduce parentheses)
Give an equivalent version of this expression by removing as many redundant parentheses as possible, without expanding the brackets or simplifying.
(x**(2**y))+(y*((z+x)**3))
Question 2 (Translate arithmetic concept into Python)
You are given a list of numbers, named numbers, containing 3 integers. Write a python expression (one line) that evaluates to True if and only if the product of any two numbers in the given list is greater than the sum of all three numbers.
Note: the product of two numbers, x and y is x*y.
Question 3 (List/table access)
You are given a table, car_count, which has three columns, day (string), hour (integer in 24 hour format) and number of cars (positive integer), that contain the count of cars that pass through an intersection. For example:
car_count = [['Monday',0,0],['Monday',1,0], ...,['Wednesday',13,7],...]
Note that the table can have any number of rows.
Write a Python code that determines the day and hour in which a maximum number of cars passes through, out of the data stored in the car_count table. If there are more than one day plus hour that has the maximum value, consider the first occurrence only. Store your answers in two different variables, one for the day and the other for the hour.
Question 4 (Translate complex logical condition)
Write a function, common_neighbours(g, x, y), that takes in an adjacency matrix representation of a graph, g, and a vertex x, and a vertex y, and returns the list of vertices that are neighbours of both x and y.
Note: a neighbour of a given vertex is directly connected to that vertex by an edge.
Step by step
Solved in 5 steps with 6 images