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 float() method will converts the number into a number with a decimal point.
The input() method, can be used to ask the user for input.
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 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 i is not equals to 1 or 2, the system will output the error message and terminate the program.
Draw a flowchart or write a code to convert an angle from degrees to radians, or from radians to degrees. The input will be an angle in degrees or radians, the output will be the angle in radians or degrees respectively.
The print() built-in function displays the specified string to the output. In this case, we use print() function to outp the result.
Since Python will ignore string literals that are not assigned to a variable, you can add a multiline string (triple quotes) in your code, and place your comment inside it
X
The import statement is used to get access to code from another module by importing the file/function. In this case, math is imported to provides access to the mathematical functions such as math.pi.
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
import math
i = int(input("Input 1 or 2, where 1 indicates that the next input value is degrees, and 2 indicates that the next input value is in radians: "))
#input x based on value of i
if i==1:
x = float(input("Input x where x is a value in degrees: "))
output = x * math.pi/180
elif i==2:
x = float(input("Input x where x is a value in radians: "))
output = x * 180/math.pi
else:
print(f'Invalid input. ')
quit()
print(f'Output value: {output}. ')
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 output for future use.