Print 'Hello, World!' to console.
print("Hello, World!")
print("I'm Sanzu")Run the program:
python hello.pyOutput:
Hello, World!
I'm Sanzu
A simple Python program that calculates the area and circumference of a circle.
- Area: π × r²
- Circumference: 2 × π × r
area = 3.14 * radius * radius
circumference = 2 * 3.14 * radiusRun the program:
python areaCircle.pyEnter the radius when prompted:
Enter radius: 5
Area of Circle: 78.5
Circumference of Circle: 31.4Prints a star pyramid pattern based on user input.
*
***
*****
*******
*********
How it works:
- Loop through each row from 1 to
rows - Calculate spaces:
rows - i(decreases each row) - Calculate stars:
2 * i - 1(odd numbers: 1, 3, 5, 7...) - Print spaces and stars using string multiplication
Run the program:
python pyramid.pyExample trace for 5 rows:
Row 1: spaces=4, stars=1 → *
Row 2: spaces=3, stars=3 → ***
Row 3: spaces=2, stars=5 → *****
Row 4: spaces=1, stars=7 → *******
Row 5: spaces=0, stars=9 → *********
A simple Python program that calculates the area of a triangle based on user input.
Run the program:
python areaTriangle.pyEnter the base and height when prompted:
Enter height: 10
Enter base: 5
-------------------------
Area of Triangle: 25.0
Requirements:
- Python 3.x
Formula: The program uses the standard triangle area formula.
Area = ½ × base × heightA simple Python program that calculates the power of a number. This program takes two inputs from the user (base and exponent) and calculates the result of base raised to the power of exponent using Python's exponentiation operator (**).
Enter the base and exponent when prompted:
Enter the base number: 2
Enter the exponent: 8
-------------------------
2^8 = 256
Requirements:
- Python 3.x
Run the program:
python exponentPower.pyHow It Works:
- Prompts user for a
basenumber - Prompts user for an
exponent - Calculates
base^exponent - Displays the result in a formatted output
Author: heysanzu
