fork download
  1. # Function to add two numbers
  2. def add_numbers(num1, num2):
  3. return num1 + num2
  4.  
  5. # Main function
  6. def main():
  7. # Input: Get two numbers from the user
  8. try:
  9. number1 = float(input("Enter the first number: "))
  10. number2 = float(input("Enter the second number: "))
  11.  
  12. # Process: Add the two numbers
  13. result = add_numbers(number1, number2)
  14.  
  15. # Output: Display the result
  16. print(f"The sum of {number1} and {number2} is: {result}")
  17. except ValueError:
  18. print("Please enter valid numbers.")
  19.  
  20. # Run the main function
  21. if __name__ == "__main__":
  22. main()
Success #stdin #stdout 0.02s 25868KB
stdin
Standard input is empty
stdout
# Function to add two numbers
def add_numbers(num1, num2):
    return num1 + num2

# Main function
def main():
    # Input: Get two numbers from the user
    try:
        number1 = float(input("Enter the first number: "))
        number2 = float(input("Enter the second number: "))
        
        # Process: Add the two numbers
        result = add_numbers(number1, number2)
        
        # Output: Display the result
        print(f"The sum of {number1} and {number2} is: {result}")
    except ValueError:
        print("Please enter valid numbers.")

# Run the main function
if __name__ == "__main__":
    main()