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 split() method splits a string into a list.
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.
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 y 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 a is equals to 0, the system will output the error message and terminate the program.
Write a code or draw a flowchart to find the bearing of B from A, when the bearing of A from B is given. The input is the bearing of A from B.
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
#input x, where x represents the bearing of A from B x = int(input("Input x, where x represents the bearing of A from B: ")) #set y=0 where y represents the bearing of B from A y = 0 #check is 0<=x<=180 and calculate y if x>=0 and x<=180:     y = 180 + x else:     y = x - 180 #check is y a 3-digit number and add 0 infront to make y 3-digit number if y<10:     print(f'The bearing of B from A is 00{y}. ') elif y<100 and y>=10:     print(f'The bearing of B from A is 0{y}. ') else:     print(f'The bearing of B from A is {y}. ')
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.