Skip to content

skalaliya/skema

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Rectangle Area and Perimeter Calculator This simple Python script calculates the area and perimeter of a rectangle based on user input. It serves as an introductory example for beginners to understand basic concepts in Python programming, such as functions, user input, calculations, and error handling.

Getting Started These instructions will help you set up and run the script on your local machine for learning and development purposes.

Prerequisites Python 3.x installed on your computer A text editor or an Integrated Development Environment (IDE) like VSCode, PyCharm, or any other of your choice. Running the Script Clone the Repository: sh Copy code git clone https://github.com/yourusername/rectangle_chandan.git Navigate to the Directory: sh Copy code cd rectangle_chandan Run the Script: sh Copy code python rectangle_chandan.py How It Works The script defines a function rectangle() which performs the following steps:

Prompts the user to enter the length and breadth of the rectangle. Calculates the area and perimeter of the rectangle. Prints the calculated area and perimeter. The script also includes error handling to manage invalid inputs gracefully.

Example Usage sh Copy code Enter the length of the rectangle: 5 Enter the breadth of the rectangle: 3 The area of the rectangle is 15.0 square units. The perimeter of the rectangle is 16.0 units. Code Explanation python Copy code def rectangle(): """ This function prompts the user to enter the length and breadth of a rectangle, then calculates and prints the area and perimeter of the rectangle. """ try: length = float(input("Enter the length of the rectangle: ")) breadth = float(input("Enter the breadth of the rectangle: "))

    # Calculate area
    area = length * breadth
    
    # Calculate perimeter
    perimeter = 2 * (length + breadth)
    
    # Print the results
    print(f"The area of the rectangle is {area} square units.")
    print(f"The perimeter of the rectangle is {perimeter} units.")

except ValueError:
    print("Invalid input! Please enter numerical values for length and breadth.")

Call the rectangle function

if name == "main": rectangle() Key Points: Function Definition: rectangle() function encapsulates the logic for area and perimeter calculation. User Input: The input() function is used to take user input. Error Handling: The try-except block handles non-numeric inputs gracefully. Formatted Output: The print() function with f-strings is used for clear and readable output. Main Guard: if name == "main": ensures that the function runs only when the script is executed directly. Contributing Feel free to fork the repository and submit pull requests. For major changes, please open an issue first to discuss what you would like to change.

License This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages