forked from dinabseiso/HW02
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHW02_ex05_04.py
74 lines (59 loc) · 2.24 KB
/
HW02_ex05_04.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
# HW02_ex05_04
# If you are given three sticks, you may or may not be able to arrange them in a
# triangle. For example, if one of the sticks is 12 inches long and the other
# two are one inch long, it is clear that you will not be able to get the short
# sticks to meet in the middle. For any three lengths, there is a simple test to
# see if it is possible to form a triangle:
# If any of the three lengths is greater than the sum of the other two, then
# you cannot form a triangle. Otherwise, you can. (If the sum of two lengths
# equals the third, they form what is called a "degenerate" triangle.)
# (1) Write a function named is_triangle that takes three integers as arguments,
# and that prints either "Yes" or "No," depending on whether you can or cannot
# form a triangle from sticks with the given lengths.
# (2) Write a function that prompts the user to input three stick lengths,
# converts them to integers, and uses is_triangle to check whether sticks with
# the given lengths can form a triangle.
################################################################################
# Write your functions below:
# Body
""""def is_triangle_2(s1,s2,s3):
if ((s1>s2+s3) or (s2>s1+s3) or (s3>s1+s2)):
print("No")
elif ((s1==s2+s3) or (s2==s1+s3) or (s3==s1+s2)):
print("Degenerate")
else:
print("Yes")"""
def is_triangle(s1,s2,s3):
if ((s1<s2+s3) and (s2<s1+s3) and(s3<s1+s2)):
print("Yes")
elif ((s1==s2+s3) or (s2==s1+s3) or (s3==s1+s2)):
print("Degenerate")
else:
print("No")
def is_triangle_mod():
s11=input("enter first side:")
s22=input("enter second side:")
s33=input("enter third side:")
s1=int(s11)
s2=int(s22)
s3=int(s33)
is_triangle(s1,s2,s3)
# Write your functions above:
################################################################################
def main():
# """Call your functions within this function.
# When complete have four function calls in this function
# for is_triangle (we want to test the edge cases!):
# is_triangle(1,2,3)
# is_triangle(1,2,4)
# is_triangle(1,5,3)
# is_triangle(6,2,3)
# and a function call for
# check_stick_lengths()
# """p
print("Hello World!")
is_triangle(6,2,3)
is_triangle_mod()
if __name__ == "__main__":
main()