0% found this document useful (0 votes)
21 views2 pages

ITEC 136 Homework 2 Name

The document describes two programming assignments: 1) A program that prompts a user to enter three sides of a triangle, uses a triangle_type() function to determine if the sides form a triangle and if so the type (equilateral, isosceles, or scalene), and prints the results. 2) A program with an is_prime() function that takes a number and returns True if it is a prime number or False if it is not, and the main program prompts for a number and prints the result.

Uploaded by

Victor Cabrejos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

ITEC 136 Homework 2 Name

The document describes two programming assignments: 1) A program that prompts a user to enter three sides of a triangle, uses a triangle_type() function to determine if the sides form a triangle and if so the type (equilateral, isosceles, or scalene), and prints the results. 2) A program with an is_prime() function that takes a number and returns True if it is a prime number or False if it is not, and the main program prompts for a number and prints the result.

Uploaded by

Victor Cabrejos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

ITEC 136 Homework 2 Name: _____________________

1. [10 points] Write a program that prompts user to enter three sides of a triangle. The
program should determine if the three sides can form a triangle. If the three sides can
form a triangle, then determine the type of the triangle.
There are three types of triangles:

o Equilateral triangle (all 3 sides are equal)


o Isosceles triangle (two sides are equal, the third side is of a different length)
o Scalene triangle (all 3 sides are of different lengths)

The program should have a function called triangle_type() that takes 3 parameters, the
lengths of each side. The triangle_type() function should return Equilateral, Isosceles,
or Scalene according to the descriptions above. Do not use global variables. Function
parameters must be used.

Sample output:
Enter side 1 length: 5
Enter side 2 length: 5
Enter side 3 length: 5
Triangle with lengths 5.0, 5.0 and 5.0 is an Equilateral
triangle.

Enter side 1 length: 5


Enter side 2 length: 5
Enter side 3 length: 4
Triangle with lengths 5.0, 5.0 and 4.0 is an Isosceles triangle.

Enter side 1 length: 10


Enter side 2 length: 5
Enter side 3 length: 30
Triangle with lengths 10.0, 5.0 and 30.0 cannot form a triangle.

2. [10 points] Write a program that determines if the number entered is a prime number.
The program should have a function called is_prime(num) that takes a single integer
argument and returns True when the argument is a prime number, and False otherwise.

Hint: Prime number is a positive number whose only factors are 1 and itself.

Here is sample output:


Enter an integer: 19
19 is a prime number.

Enter an integer: 136


136 is not a prime number.

You might also like