Re: Programming in python
Hello, a few remarks about your program: it works well but ...
(1) add the line
Code:
# -*- coding: utf-8 -*-
at the beginning of your code, if you have a problem with accents in your text
(2) does not
it seems simple but in reality it is a source of error, for later, when your code has grown.
(3) instead of:
Code:
a = float (a)
b = float (b)
c = float (c)
You can also write:
Code:
a, b, c = float (a), float (b), float (c)
Re: Programming in python
Quote:
Originally Posted by
Katty
Hello, a few remarks about your program: it works well but ...
Not necessarily, it depends potential platform: it makes strict equality on floating
Re: Programming in python
You must use an epsilon (basically you determine a margin of error, you subtracted the two numbers to compare and if the result is less than your margin of error you consider that they are equal).
There are other strategies, but they impose limitations (and potentially impact the level of performance) and are not necessarily used as appropriate: to make his calculations with integers (by adding powers of 10 baseline, this is how the calculations are made monetary) or by the fixed-point arithmetic or decimal. In python, the role of the decimal module precisely.
Re: Programming in python
am not sure why u wrote this code like that but but i made a few changes to it myself
Code:
# -*- coding: utf-8 -*-
import math
a=raw_input("dimension of the side BC: " )
b=raw_input("dimension of the side AC: " )
c=raw_input("dimension of the side AB: " )
a=float(a)
b=float(b)
c=float(c)
x1 = math.sin(a/c)
x2 = math.sin(b/c)
x3 = math.tan(c/b)
x=x1+x2+x3
pi=3.142
if x==pi:
if x1==(pi/2) or x2==(pi/2) or x3==(pi/2):
print "ABC is a triangle"
elif x1==x2 or x2==x3 or x1==x3:
print "ABC is a isosceles triangle"
elif x1==x2 and x2==x3 and x3==(pi/3):
print "ABC is an equilateral triangle"
else:
print "ABC is any triangle"
else:
print "ABC isn't a triangle"