0% found this document useful (0 votes)
36 views4 pages

Palaganas, Rod Diego T. Bscpe - Iv

This document contains 3 programming scripts written by Rod Diego T. Palaganas. The first script calculates the circumference of a circle given the radius. The second script calculates the area of a square and right triangle given different inputs like base/height, sides/angle, or all three sides. The third script converts a length in centimeters to meters, kilometers, and miles depending on the user's selection.

Uploaded by

Reggie Palaganas
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)
36 views4 pages

Palaganas, Rod Diego T. Bscpe - Iv

This document contains 3 programming scripts written by Rod Diego T. Palaganas. The first script calculates the circumference of a circle given the radius. The second script calculates the area of a square and right triangle given different inputs like base/height, sides/angle, or all three sides. The third script converts a length in centimeters to meters, kilometers, and miles depending on the user's selection.

Uploaded by

Reggie Palaganas
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/ 4

Palaganas, Rod Diego T.

BSCpE - IV

1. Create a script that will let the user enter the radius of a circle and computer for its
circumference.

from math import pi

r = float(input ("Input the radius of the circle : "))

print ("The circumference of the circle with radius " + str(r) + " is: " + str(2*pi * r))

2. Create a script that will calculate the area of a square and a right triangle.

RIGHT TRIANGLE

import math
import sys

print("Type 1 if the base and height is given")


print("Type 2 if the 2 sides and the angle is given")
print("Type 3 if you know the 3 sides")

type = int(input(" Type 1,2 or 3: "))

# Check for invalid inputs

while(type !=1 and type !=2 and type !=3):


type = int(input("Type 1, 2 or 3: "))

# A= (1/2)*base*height

if(type == 1):
base = float(input("Enter the base: "))
height = float(input("Enter the height: "))
area = (1/2)*base*height
print("The area of the triangle is ", area)

# A = (1/2)*side1*side2*sin(angle)

if(type == 2):

side1 = float(input("Enter side 1: "))


side2 = float(input("Enter side 2: "))
angle = float(input("Enter the angle in degrees: "))
anglerad = angle*math.pi/180
area = 5*side1*side2*math.sin(anglerad)
print("The area of the triangle is ", area)

# A = sqrt(s*(s - a)*(s - b)*(s - c))

if(type == 3):

side1 = float(input("Enter side 1: "))


side2 = float(input("Enter side 2: "))
side3 = float(input("Enter side 3: "))
sp = (side1 * side2 * side3)/2
area = math.sqrt(sp*(sp - side1)*(sp - side2)*(sp - side3))
print("The area of the triangle is ", area)
AREA OF A SQUARE

import math
import sys

height = float(input("Enter the Height: "))


width = float(input("Enter the Width: "))
area = width*height

print("The area of the square is ", area)

3. Create a program that will convert the corresponding length in cm to m, km and


miles.

import math
import sys

print("Type 1 to convert cm to m")


print("Type 2 to convert cm to km")
print("Type 3 to convert cm to miles")

type = int(input(" Type 1,2 or 3: "))

# Check for invalid inputs

while(type !=1 and type !=2 and type !=3):


type = int(input("Type 1, 2 or 3: "))

if(type == 1):

cm = float(input("Enter the value of cm: "))


m = cm/100
print("The value of cm to m is ", m)
if(type == 2):

cm = float(input("Enter the value of cm: "))


km = cm/100000
print("The value of cm to km is ", km)

if(type == 3):

cm = float(input("Enter the value of cm: "))


miles = 1 * 1/160934.4
print("The value of cm to miles is ", miles)

You might also like