Python Workout 04: More Fun with Functions

Level of Difficulty:

Objective: This workout is to provide more practice with creating calculations with functions.

Problem 1: Create a function that takes an angle in radians and returns the corresponding angle in degrees rounded to one decimal place.

Example

radians_to_degrees(20) ➞ 1145.9

Problem 2: Create a function that returns True when num1 is equal to num2; otherwise return False

Examples:

is_same_num(4, 8) ➞ False

is_same_num(2, 2) ➞  True

Submission

SImply post your code and a screenshot of your results.

Please format your Python code and blur it or place it in a hidden section.

This workout will be released on Thursday April 6, 2023, and the author’s solution will be posted on Wednesday April 12, 2023.

Hi ,

My submission :
Problem 1: Create a function that takes an angle in radians and returns the corresponding angle in degrees rounded to one decimal place.
image

Code
from math import pi
def radians_to_degrees(radian):
  return round(radian*180/pi,1)

Problem 2: Create a function that returns True when num1 is equal to num2; otherwise return False
image

Code
def is_same_num(num1,num2):
  return num1==num2

Thanks

Here is my solution:

import math

def radians_to_degrees(angle_rad):
    angle_deg = angle_rad * (180 / math.pi)
    angle_deg_rounded = round(angle_deg, 1)
    return angle_deg_rounded

import math 
def radians_to_degrees(r): return round(r*180/math.pi,1)
def is_same_num(x:int, y:int) : return x== y
import math

def radians_degrees_converter(radian):
    """function takes in a radian and converst it to a degree"""

    angle_converter = radian * (57.33)
    rounded_angle = round(angle_converter, 1)
    return rounded_angle

result = radians_degrees_converter(10)
print(result)

# %%
def number_test(v1, v2):
    """compares numbers and if identical returns true, otherwise returns false"""

    if v1 == v2:
        return True
    else:
        return False
    
result1 = number_test(5,5)
print(result1)

result2 = number_test(6,9)
print(result2)
1 Like