Wednesday, August 21, 2024

Program Example

 ...


  1. Calculate Area of Rectangle:

    python
    length = float(input("Enter the length of the rectangle: ")) breadth = float(input("Enter the breadth of the rectangle: ")) area = length * breadth print(f"The area of the rectangle is {area}")
  2. Calculate Area of Circle:

    python
    import math radius = float(input("Enter the radius of the circle: ")) area = math.pi * (radius ** 2) print(f"The area of the circle is {area}")
  3. Calculate Total and Percentage of Marks:

    python
    name = input("Enter the student's name: ") marks = [] for i in range(5): mark = float(input(f"Enter the mark for subject {i+1}: ")) marks.append(mark) total = sum(marks) percentage = (total / 500) * 100 print(f"Total marks: {total}") print(f"Percentage: {percentage}%")
  4. Convert Feet to Inches:

    python
    feet = float(input("Enter the distance in feet: ")) inches = feet * 12 print(f"The distance in inches is {inches}")
  5. Convert Fahrenheit to Celsius:

    python
    fahrenheit = float(input("Enter temperature in Fahrenheit: ")) celsius = (fahrenheit - 32) * 5/9 print(f"The temperature in Celsius is {celsius}")
  6. Calculate Volume of Cylinder:

    python
    import math radius = float(input("Enter the radius of the cylinder: ")) height = float(input("Enter the height of the cylinder: ")) volume = math.pi * (radius ** 2) * height print(f"The volume of the cylinder is {volume}")

You can run these programs individually depending on which task you want to perform.

No comments:

Post a Comment

Python Files and Exceptions: Unit 9

  Table of contents Reading from a File Reading an Entire File File Paths Reading Line by Line Making a List of Lines from a File Working wi...