Spaces:
Sleeping
Sleeping
GenAITech
#1
by gireeshunique - opened
๐: write a additions of two numbers
๐ค: Sure! Here's a simple Python program that adds two numbers provided by the user:
# Simple Python Program to Add Two Numbers
# Function to add two numbers
def add_numbers(num1, num2):
return num1 + num2
# Main function
def main():
# Get user input
try:
number1 = float(input("Enter the first number: "))
number2 = float(input("Enter the second number: "))
except ValueError:
print("Please enter valid numbers.")
return
# Calculate the sum
sum_result = add_numbers(number1, number2)
# Display the result
print(f"The sum of {number1} and {number2} is {sum_result}.")
# Run the program
if __name__ == "__main__":
main()
How to Run the Program:
- Copy the code into a text editor or an IDE like PyCharm or VSCode.
- Save the file with a
.pyextension, for example,add_two_numbers.py. - Open a terminal or command prompt.
- Navigate to the directory where the file is saved.
- Run the program by typing
python add_two_numbers.pyand follow the prompts.
Feel free to ask if you have any questions or need further modifications!