Description
This lab was to show and explain how to use variables and to use the math module to solve math functions. In this case, we are to solve for area by the user giving a radius and afterwards the user is to provide the program with two integers in order to receive a value for distance between two points.
Code
# Alex Charles
# Lab 1B – Variable
# Section: 9306
# February 21, 2013
# This program calculates an area of a circle.
import math
#1. Ask the user to input the radius
strRad = input (“Please provide the radius: “)
r = float(strRad)
#2. Calculate the area of the circle.
area = math.pi * math.pow(r,2)
#3. Print out the calculated area.
print (“The area of the circle with radius”, r, “is:”, area)
#This program calculates the distance of 2 points.
#1. Ask the user to input two set of points
strPt = input (“Please provide X1: “)
strPt2 = input (“Please provide X2: “)
strPt3 = input (“Please provide Y1: “)
strPt4 = input (“Please provide Y2: “)
X1 = float(strPt)
X2 = float(strPt2)
Y1 = float(strPt3)
Y2 = float(strPt4)
#2. Calculate the distance using the two set of points.
distance = math.sqrt(math.pow(X2-X1,2) – math.pow(Y2-Y1,2))
#3. Print out the calculated distance.
print (“The distance of the points”, (X1,Y1), “and”, (X2,Y2), “is”, distance)
Screenshot