pannix said:
Calculate the surface area and the volume of a sphere based on a given radius:
This course will become read-only in the near future. Tell us at community.p2pu.org if that is a problem.
Operators work with one or more objects and can perform tasks such as math, comparison, and inspection.
There are standard operators for arithmetic:
Operator | Description |
---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
// | Integer Division |
% | Modulus Division |
** | Exponent |
Additionally, you can modify a named value and assign the output of an operator to the name in one line with inline assignment operators.
>>> a_number = 1 >>> a_number += 1 >>> a_number 2 >>> a_number *= 8 >>> a_number 16 >>> a_number **= 2 >>> a_number 256 >>> a_number /= 2 >>> a_number 128 >>> a_number %= 3 >>> a_number 2 >>> 3.123 // a_number 1
Calculate the surface area and the volume of a sphere based on a given radius:
Python script that calculates the area of a rectangle:
Python script that calculates the area of a circle:
Hi all,
According to http://docs.python.org/library/operator.html operator.add(x, y) is equivalent to the expression x+y however, when I try this I get a 'not defined error'.
Could you please advice?
Do I need to declare operator as a variable?
Thanx
# Author: blanco_fam
# Calculate volumen of a sphere
radius=input("Enter Radius: ")
pi=3.141592
# Calculate
volume = 4/3*pi*float(radius)**3
print("Volume = ", volume)
# #!/usr/bin/python
#
# By dvdjaco
# Exercise 3.2
#
# Convert distances in parsecs to yards (you never know...)
d_parsec = float(raw_input('Please enter the distance in parsecs: '))
print 'The distance in yards is ' + str(d_parsec*3.374538037e+16)
#!/usr/bin/python
#filename:streampower.py
# Author: Gnuisance
# Program: Operator
base = float(raw_input('Enter length of triangle base: '))
height = float(raw_input('Enter length of triangle height: '))
area = float(0.5 * base * height)
print 'Area of triangle = ', str(area)
# Author: Landon Mayo # Program: 'Miles Per Hour' to 'Knots' Calculator ''' 1 kts = 1.15077945 mph ''' # MPH=miles per hour # KTS=Knots # Get MPH to be converted to KTS mph=raw_input("Enter Speed in Miles Per Hour: ") knot=float(1.15077945) print float(mph)/knot, "Knots Per Hour"