Question

Python Coding: For this assignment you will be using functions. You will ask the user to...

Python Coding:

For this assignment you will be using functions. You will ask the user to input some numbers. The user can enter 4 numbers. You will then return if the numbers of it forms a rectangle or a square (and if so, what is the perimeter). Remember you must use functions.

Sample Run: Example 1: Enter the next number (enter -1 when finished) > 5 Enter the next number (enter -1 when finished) > 3 Enter the next number (enter -1 when finished) > 3 Enter the next number (enter -1 when finished) > 5 Enter the next number (enter -1 when finished) > -1 Forms a rectangle with perimeter of 16

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def rectangle_or_triangle():
    lst = []
    while True:
        side = int(input("Enter the next number (enter -1 when finished) > "))
        if side == -1:
            break
        lst.append(side)
    p = lst[0] + lst[1] + lst[2] + lst[3]
    if lst[0] == lst[1] and lst[1] == lst[2] and lst[2] == lst[3]:
        return "Forms a square with perimeter of " + str(p)
    else:
        return "Forms a rectangle with perimeter of " + str(p)


def main():
    print(rectangle_or_triangle())


main()

Add a comment
Know the answer?
Add Answer to:
Python Coding: For this assignment you will be using functions. You will ask the user to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT