ILLUSTRATIVE PROGRAMS IN PYTHON
1 Hello, World! Program:
print("Hello, World!")
This program simply prints the message "Hello, World!" to the console.
2 Simple Calculator:
def add(a, b):
return a + b def subtract(a, b): return a - b def multiply(a, b): return a * b def divide(a, b): return a / b num1 = float(input("Enter the first number: ")) num2 = float(input("Enter the second number: ")) print("Sum:", add(num1, num2)) print("Difference:", subtract(num1, num2)) print("Product:", multiply(num1, num2)) print("Quotient:", divide(num1, num2))This program performs basic arithmetic operations (addition, subtraction, multiplication, and division) on two numbers provided by the user.
Comments
Post a Comment