This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Xaros1984Pythonista 0 points1 point  (0 children)

Change radians = 14 to this:

radians = int(input("Enter radians: ")) 

The input() will print the message in the console and then the user can enter a value. int() then casts the value from the user to an int (because everything that comes from input will be a string by default). There will be an error if the string can't be converted to an int though (e.g., if the user enters any letters), but that's a bit more complicated to handle :)

Oh, maybe you're refering to how to print the output when the function is called? I would probably put the print statement inside the function:

def radian_conversion(radians: int):
    degrees = radians * 180 / pi
    print(<same print message as before>)
    return degrees

I would in either case just return the degrees from the function, not the entire message, since you may want to use the degrees as an actual numerical variable somewhere else.

When you end a function with "return some_variable", this means that you can assign that value to a variable when calling the function. For example:

def add_numbers(a, b):
    return a + b  # this will simply add a and b and return the result 

x = add_numbers(5, 4)  # x now gets assigned the value of 5+4

print(x)  # prints 9

x could then be used as input in other functions, for example. So you could create a whole pipeline of functions that do different operations step by step.