gpt-4-0125-preview· openai
Suzhen/CodeChat
python code for addition of two numbers
- User
python code for addition of two numbers
- Assistant
Certainly! Here's a simple Python script that prompts the user to enter two numbers and then outputs their sum:
python# Prompt the user to input the first number num1 = float(input("Enter the first number: ")) # Prompt the user to input the second number num2 = float(input("Enter the second number: ")) # Calculate the sum of the two numbers sum = num1 + num2 # Output the result print(f"The sum of {num1} and {num2} is {sum}")This script uses
float(input())to allow users to enter decimal numbers. If you only need to work with integers, you can replacefloatwithint. Theprintstatement uses an f-string to format the output message, which is a convenient way to include variable values in strings.