how to write a function in python 3 that reads a txt file which includes three number (each line has one number) assuming these numbers are the side lengths of a triangle. The function checks the validity of the triangle and prints whether the triangle is valid or not. If is is valid, the result should also indicate the type of triangle.

Question
Asked Mar 3, 2019
6 views

how to write a function in python 3 that reads a txt file which includes three number (each line has one number) assuming these numbers are the side lengths of a triangle. The function checks the validity of the triangle and prints whether the triangle is valid or not. If is is valid, the result should also indicate the type of triangle. 

check_circle

Expert Answer

star
star
star
star
star
1 Rating
Step 1

Algorithim

Start

Open a file in read mode

Read a line from file and store the number in variable a

Read a line from file and store the number in variable b

Read a line from file and store the number in variable c

if (a + b > c) and (a + c > b) and (b + c > a)

then print "Triangle is valid"

if (a==b) and (b==c)
then print "Equilateral Triangle"
else if (a!=b) and (b!=c) and (a!=c)
then print "Scalene Triangle"
else
print "Isoceles Triangle"

else print "Triangle is NOT valid"

Stop

Step 2

Python code

inputFile = open("numbers.txt", "r")
a=int(inputFile.readline())
b=int(inputFile.readline())
c=int(inputFile.readline())
if (a + b > c) and (a + c > b) and (b + c > a) :
print("Triangle is valid")
if (a==b) and (b==c):
print("Equilateral Triangle")
elif (a!=b) and (b!=c) and (a!=c):
print("Scalene Triangle")
else:
print("Isoceles Triangle")
else:
print("Triangle is NOT valid")

Step 3

Input File

File name: numbers.txt

7
10
5

...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Programing Language

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: How can I create a decoder and a multiplexer in a circuit? The decoder has a 3 bit select input and ...

A: A decoder is a circuit which has n inputs and 2n outputs. So if there are 3 inputs to a decoder it w...

question_answer

Q: 11.9: Speakers' Bureau Write a program that keeps track of a speaker's bureau. The program should us...

A: We use C++ language and validate input for fees so that only integers are accepted. A struct data st...

question_answer

Q: JAVA PROGRAM NEED TO BE SUBMITTED TOMORROW   you operate 3 hot dog stands distributed throughout tow...

A: The following override methods are created along with @Override annotation:equalsfinalizetoStringThe...

question_answer

Q: A pet shop wants to give a discount to its clients if they buy one or more pets and at least four ot...

A: The program has two main parts – the part which receives the input and the part which validates the ...

question_answer

Q: l Sprint LTE 09:28 9 morgan.blackboard.com Bb Courses Course Material Assignment 3 1. Use the variab...

A: Hey, since there are multiple questions posted, I answer first three questions. If you want any spec...

question_answer

Q: Write a PL/SQL block to accept a date from the user and print the day and the date as shown below. U...

A: Solution:Given data,The PL/SQL code read the user input of date and display the day and the date in ...

question_answer

Q: What are the errors in the following code?

A: Given below are the errors found in the code send by you along with an error free code.

question_answer

Q: (Method Overloading) Given the following methods, write down the printed output of themethod calls: ...

A: Answer with Explanation:“doSomething(5)” contains an argument integer “5” and it is called to the “d...

question_answer

Q: Normalization               Repair the ER Diagrams into at least 1nf, 2nf and 3nf Give explanations...

A: Hi due to lack of adequate information we are unable to provide any solution. Please provide us more...