Professional Documents
Culture Documents
Progrestest 1
Progrestest 1
Progrestest 1
QE : 170215
Class: AI17C
Code Insert\Scrennshot
Insert\Scrennshot
Code
import math
a = float(input("Enter a:"))
b = float(input(" Enter b:"))
c = float(input(" Enter c:"))
#because real numbers, so
we using float
if(((a+b)>c) and ((a+c)>b)
and ((b+c)>a)) :
#check if it is a triangle or
not
perimeter = (a+b+c)
#perimeter of triangle
p=(a+b+c)/2
#half perimeter of triangle
The_area_of_triangle=
""
#create a variable that
stores the result as empty
The_area_of_triangle=
math.sqrt(p*(p-a)*(p-b)*(p-
c))
#Using Heron formula
print(" the perimeter
of triangle is : ", perimeter)
print("the area of
triangle
is:",The_area_of_triangle)
#Display the area of
triangle on the screen
else:
print("a, b, c are not
side of a triangle ")
Output:
Insert\Scrennshot
Code
#program assign a different
name to function and call it
through the new name
def display_student(name,
age):
#create function with 2
variable : name , age
print(name, age)
#call first name
display_student("Minh", 100)
show_student =
display_student
show_student("Quang", 19)
Insert\Scrennshot
Code
n = int(input(" Please enter
n:"))
S1=0
S2=1
S3=0
if n<=5:
print ( " Re-enter n>5")
else:
for i in range ( 1, n+1 ):
S1= S1 + i # calculate S1
= 1 + 2 + 3 + ... + n.
S2=S2*i #3.calculate S2 =
n!