Close Menu

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    Mastering Python Modules: 10 Practical Mini Projects with Complete Solutions

    March 25, 2025

    What is Python? How to Set It Up on Your PC

    March 24, 2025

    What is the Difference Between TypeScript and JavaScript?

    March 11, 2025
    Facebook X (Twitter) Instagram
    • Demos
    • Buy Now
    Facebook X (Twitter) Instagram Pinterest Vimeo
    Sachiya TechSachiya Tech
    • Home
    • Programming Languages
      • JavaScript
      • Laravel
      • Java
      • Node JS
    • About Us
    • Disclaimer
    • Privacy Policy
    • Contact
    Subscribe
    Sachiya TechSachiya Tech
    Home»Uncategorized»Mastering Python Modules: 10 Practical Mini Projects with Complete Solutions
    Uncategorized

    Mastering Python Modules: 10 Practical Mini Projects with Complete Solutions

    SachinthaBy SachinthaMarch 25, 2025No Comments2 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Question 1

    Write a Python application as per the instructions given below:

    i) Create a python module named validate.py to receive three integers and reject them if they are equal.
    ii) Create a python module named maxmin.py to include two functions namely small and large to receive three integers and return the smaller and the larger respectively.
    iii) Write a driver code called driver.py that can receive three integers from the user and deploy validate.py and maxmin.py modules to display the smaller and the larger numbers respectively.

    Answer,

    i) This module checks if all three integers are equal. If they are, it will raise a ValueError.

    # validate.py
    
    def validate(a, b, c):
        if a == b == c:
            raise ValueError("All three numbers are equal. Input rejected.")
        return True
    

    ii) This module includes two functions:

    large() returns the largest of the three numbers.

    small() returns the smallest of the three numbers.

    # maxmin.py
    
    def small(a, b, c):
        return min(a, b, c)
    
    def large(a, b, c):
        return max(a, b, c)
    

    iii) This is the main script that takes user input, validates the numbers using validate.py, and then finds the smallest and largest using maxmin.py.

    # driver.py
    
    from validate import validate
    from maxmin import small, large
    
    def main():
        try:
            # Get input from user
            a = int(input("Enter first number: "))
            b = int(input("Enter second number: "))
            c = int(input("Enter third number: "))
    
            # Validate numbers
            validate(a, b, c)
    
            # Find and display results
            print("Smallest number is:", small(a, b, c))
            print("Largest number is:", large(a, b, c))
    
        except ValueError as ve:
            print("Validation Error:", ve)
        except Exception as e:
            print("An error occurred:", e)
    
    if __name__ == "__main__":
        main()
    

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleWhat is Python? How to Set It Up on Your PC
    Sachintha
    • Website

    Related Posts

    Uncategorized

    What is Python? How to Set It Up on Your PC

    March 24, 2025
    Uncategorized

    What is the Difference Between TypeScript and JavaScript?

    March 11, 2025
    Uncategorized

    How to Boost Your Wi-Fi Signal at Home

    December 25, 2024
    Add A Comment
    Leave A Reply Cancel Reply

    Demo
    Top Posts

    How To Setup Your Gaming PC In Your Living Room

    November 9, 202452 Views

    The Future of Cities: Where Innovation Meets Green Living

    November 2, 202440 Views

    How to Boost Your Wi-Fi Signal at Home

    December 25, 202429 Views
    Stay In Touch
    • Facebook
    • YouTube
    • TikTok
    • WhatsApp
    • Twitter
    • Instagram
    Latest Reviews

    Subscribe to Updates

    Get the latest tech news from FooBar about tech, design and biz.

    Demo
    Most Popular

    How To Setup Your Gaming PC In Your Living Room

    November 9, 202452 Views

    The Future of Cities: Where Innovation Meets Green Living

    November 2, 202440 Views

    How to Boost Your Wi-Fi Signal at Home

    December 25, 202429 Views
    Our Picks

    Mastering Python Modules: 10 Practical Mini Projects with Complete Solutions

    March 25, 2025

    What is Python? How to Set It Up on Your PC

    March 24, 2025

    What is the Difference Between TypeScript and JavaScript?

    March 11, 2025

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    Facebook X (Twitter) Instagram Pinterest
    • Home
    • Buy Now
    © 2025 ThemeSphere. Designed by ThemeSphere.

    Type above and press Enter to search. Press Esc to cancel.