gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
Wirte a python programmer to add two number
- User
Wirte a python programmer to add two number
- Assistant
Sure! Here's a Python program to add two numbers:
python# Function to add two numbers def add_numbers(num1, num2): sum = num1 + num2 return sum # Input the numbers from the user number1 = float(input("Enter the first number: ")) number2 = float(input("Enter the second number: ")) # Call the add_numbers function and store the result in a variable result = add_numbers(number1, number2) # Display the result print("The sum of", number1, "and", number2, "is", result)In this program, we define a function
add_numbers()that takes two parameters (num1andnum2) representing the numbers to be added. The function calculates the sum of the two numbers and returns it.We then prompt the user to input two numbers using the
input()function and store them innumber1andnumber2variables. We pass these values to theadd_numbers()function and store the result in theresultvariable.