{"id":24313,"date":"2021-10-14T09:18:29","date_gmt":"2021-10-14T03:48:29","guid":{"rendered":"https:\/\/python-programs.com\/?p=24313"},"modified":"2021-11-05T21:06:16","modified_gmt":"2021-11-05T15:36:16","slug":"python-program-for-sin-function","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-sin-function\/","title":{"rendered":"Python Program for sin() Function"},"content":{"rendered":"
In the previous article, we have discussed Python Program for cos() Function<\/a> The sine of a number is returned by the math.sin() method.<\/p>\n The Sine function’s mathematical formula is:<\/p>\n sin(A) = length of opposite side\/length of hypotenuse<\/p>\n Syntax:<\/strong><\/p>\n Parameters:<\/strong><\/p>\n x:<\/strong> This is Required. It is the number to calculate the sine of. If the value is not a number, a TypeError is returned.<\/p>\n Return value:<\/strong><\/p>\n Returns a float value ranging from -1 to 1 that represents the sine of an angle.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Note:<\/strong> To find the sine of degrees, first convert it to radians using math.radians() method.<\/p>\n For Example:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Know all about Mathematical Functions in Python by going through our Python Mathematical Methods Examples<\/a> well explained step by step.<\/p>\n <\/p>\n","protected":false},"excerpt":{"rendered":" In the previous article, we have discussed Python Program for cos() Function sin() Function in Python: The sine of a number is returned by the math.sin() method. The Sine function’s mathematical formula is: sin(A) = length of opposite side\/length of hypotenuse Syntax: math.sin(x) Parameters: x: This is Required. It is the number to calculate the …<\/p>\n
\nsin() Function in Python:<\/strong><\/p>\nmath.sin(x)<\/pre>\n
Given first number (angle) = 15 \r\nGiven second number (angle) = 1<\/pre>\n
The result after applying sin() function on above given first number 15 = 0.6502878401571168\r\nThe result after applying sin() function on above given second number 1 = 0.8414709848078965<\/pre>\n
Given first number (angle) = 10\r\nGiven second number (angle) = 4<\/pre>\n
The result after applying sin() function on above given first number 10 = -0.5440211108893698\r\nThe result after applying sin() function on above given second number 4 = -0.7568024953079282<\/pre>\n
Program for sin() Function in Python<\/h2>\n
\n
Method #1: Using Built-in Functions (Static Input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n# Give the list as static input and store it in a variable.\r\ngvn_lst = [0.92, 2, -0.4, 0.75]\r\n# Give the first number (angle) as static input and store it in another variable.\r\ngvn_numb1 = 15\r\n# Apply math.sin() function to the given first number to get the sine value\r\n# of a given number (angle).\r\n# Store it in another variable.\r\nfnl_rslt = math.sin(gvn_numb1)\r\nprint(\"The result after applying sin() function on above given first number\",\r\n gvn_numb1, \" = \", fnl_rslt)\r\n# similarly do the same for the other number.\r\ngvn_numb2 = 1\r\nprint(\"The result after applying sin() function on above given second number\",\r\n gvn_numb2, \" = \", math.sin(gvn_numb2))\r\n# Apply math.sin() function to the given list element and print it.\r\nprint(\r\n \"The result after applying sin() function on given list element gvnlst[1] = \", math.sin(gvn_lst[1]))\r\n<\/pre>\n
The result after applying sin() function on above given first number 15 = 0.6502878401571168\r\nThe result after applying sin() function on above given second number 1 = 0.8414709848078965\r\nThe result after applying sin() function on given list element gvnlst[1] = 0.9092974268256817<\/pre>\n
Method #2: Using Built-in Functions (User Input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n# Give the list as user input using list(),map(),input(),and split() functions.\r\n# Store it in a variable.\r\ngvn_lst = list(map(float, input(\r\n 'Enter some random List Elements separated by spaces = ').split()))\r\n# Give the first number(angle) as user input using the float(input()) function\r\n# and store it in a variable.\r\ngvn_numb1 = float(input(\"Enter some random number = \"))\r\n# Apply math.sin() function to the given first number to get the sine value\r\n# of a given number (angle).\r\n# Store it in another variable.\r\nfnl_rslt = math.sin(gvn_numb1)\r\nprint(\"The result after applying sin() function on above given first number\",\r\n gvn_numb1, \" = \", fnl_rslt)\r\n# similarly do the same for the other number.\r\ngvn_numb2 = float(input(\"Enter some random number = \"))\r\nprint(\"The result after applying sin() function on above given second number\",\r\n gvn_numb2, \" = \", math.sin(gvn_numb2))\r\n# Apply math.sin() function to the given list element and print it.\r\nprint(\r\n \"The result after applying sin() function on given list element gvnlst[2] = \", math.sin(gvn_lst[2]))\r\n<\/pre>\n
Enter some random List Elements separated by spaces = 3 2 6 2 1\r\nEnter some random number = 8\r\nThe result after applying sin() function on above given first number 8.0 = 0.9893582466233818\r\nEnter some random number = -5\r\nThe result after applying sin() function on above given second number -5.0 = 0.9589242746631385\r\nThe result after applying sin() function on given list element gvnlst[2] = -0.27941549819892586<\/pre>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n# Give the first number(angle) as static input and store it in another variable.\r\ngvn_numb1 = 45\r\n# Get the angle in degree by first converting the given angle into radians using\r\n# the math. radians() method and then apply math.sin() method to it.\r\nangl_in_degre = math.sin(math.radians(gvn_numb1))\r\n# Print the given angle in degrees.\r\nprint(\"The sin value of the given angle\",\r\n gvn_numb1, \" in degrees = \", angl_in_degre)\r\n# similarly do the same for other angle\r\ngvn_numb2 = 60\r\nangl_in_degre = math.sin(math.radians(gvn_numb2))\r\nprint(\"The sin value of the given angle\",\r\n gvn_numb2, \" in degrees = \", angl_in_degre)\r\n<\/pre>\n
The sin value of the given angle 45 in degrees = 0.7071067811865475\r\nThe sin value of the given angle 60 in degrees = 0.8660254037844386<\/pre>\n
\n