Using try and except statement for exception handling, using raise to throw out the exception and stop the program.
If the previous condition is false, the program will execute statement inside else block to calculate x1 and x2 values. The math.sqrt() function will be used to calculate the square root of D.
The len() function returns the number of items in an object.
The input() method, can be used to ask the user for input. The float() method will converts the number into a number with a decimal point. The split() method splits a string into a list.
An array is a special variable, which can hold more than one value at a time, and you can access the values by referring to an index number. The index number start with 0. In this case, we use the user input list as array.
A variable stores a value that can be referred to or modified later in the program. In this case, the result of calculation will store in variable theta, variable sin_ACB and variable S for future use.
Comments starts with a "#" symbol, and Python will ignore them. Comment can be used to explain Python code, and make the code more readable.
When the system encounters the quit() function, it terminates the execution of the program completely. In this case, if the value of n is not equals to 9, the system will output the error message and terminate the program.
Draw a flowchart or write a code to translate a triangle ABC to a triangle DEF by the vector . The input consists of the coordinates of A, B and C, and the vector . The output is the coordinates of D, E and F.
The print() built-in function displays the specified string to the output. In this case, we use print() function to output the result.
The append() method appends an element to the end of the list. The pop() method removes the element at the specified position and returns the removed value.
X
The sort() method sorts the list ascending by default.
The import statement is used to get access to code from another module by importing the file/function. In this case, statistics is a built-in module that you can use to calculate mathematical statistics of numeric data.
In this case, if the D < 0 condition is true, it will execute statement inside if block, if false, it will check next condition.
Game Code
The for loop repeats codes within itself for a fixed number of times determined by the specified expression.
00:00
A = list(map(float,input("Type coordinates of A without the brackets e.g. If the coordinates are \"(1,2)\", type \"1,2\": ").split(","))) B = list(map(float,input("Type coordinates of B without the brackets e.g. If the coordinates are \"(1,2)\", type \"1,2\": ").split(","))) C = list(map(float,input("Type coordinates of C without the brackets e.g. If the coordinates are \"(1,2)\", type \"1,2\": ").split(","))) PQ = list(map(float,input("Type vector PQ without the brackets e.g. If the vector is \”(1 2)\", type \"1,2\": ").split(","))) #Add the first input value of PQ to the x coordinate of A,B and C Dx = A[0]+PQ[0] Ex = B[0]+PQ[0] Fx = C[0]+PQ[0] #Add the second input value of PQ to the y coordinate of A,B and C Dy = A[1]+PQ[1] Ey = B[1]+PQ[1] Fy = C[1]+PQ[1] print(f'The coordinates of D, E and F are ({Dx},{Dy}), ({Ex},{Ey}) and ({Fx},{Fy}).')
If the previous condition is false, the program will check elif condition D == 0, if true, it will execute statement inside elif block to calculate x0 and output the result. If false, it will check next condition.
A variable stores a value that can be referred to or modified later in the program. In this case, the result of calculation will store in variable C and n for future use.
The if...elif...else statement is used for decision making. In this case, we use this to decide the final output of the program. Only one block among the several blocks of if...elif...else is executed according to the condition.