Created
February 6, 2012 03:08
-
-
Save liamlah/1749296 to your computer and use it in GitHub Desktop.
Python Frequency/wavelength converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print "This script can convert wavelengths to frequencies or vice versa." | |
sol = 299792458.00 #this is the speed of light in m/s | |
#sol = 300000000.00 #this is the speed of light in m/s | |
print "do you have a (1) a wavelength or (2) a frequency?" | |
choice = raw_input() | |
if choice == "1": | |
print "Ok, Please enter your wavelength in Metres. (do not use scientific notation)" | |
wavelength = float(raw_input ()) | |
answerfreq = sol / wavelength | |
print "the frequency is %rhz" % answerfreq | |
if wavelength <= 1000 and wavelength >= 0.01: | |
print "Radio Wave" | |
elif wavelength <= 0.01 and wavelength >= 0.00001: | |
print "Microwave" | |
elif wavelength <= 0.00001 and wavelength >= 0.0000005: | |
print "Infra Red" | |
elif wavelength <= 0.0000005 and wavelength >= 0.00000001: | |
print "Visible Light" | |
elif wavelength <= 0.00000001 and wavelength >= 0.0000000001: | |
print "Ultra Violet" | |
elif wavelength <= 0.0000000001 and wavelength >= 0.000000000001: | |
print "X-Rays" | |
elif wavelength <= 0.000000000001: | |
print "Gamma Rays" | |
else: | |
print "not an existing band" | |
elif choice == "2": | |
print "Ok, Please enter your frequency in Hz. (do not use scientific notation)" | |
frequency = float(raw_input ()) | |
answerlamda = sol / frequency | |
print "the wavelength is %rm " % answerlamda | |
if answerlamda >= 1000: | |
print "Radio Wave" | |
elif answerlamda in range (0.01, 0.00001): | |
print "Microwave" | |
elif answerlamda in range (0.00001, 0.0000005): | |
print "Infra Red" | |
elif answerlamda in range (0.0000005, 0.00000001): | |
print "Visible Light" | |
elif answerlamda in range (0.00000001, 0.0000000001): | |
print "Ultra Violet" | |
elif answerlamda in range (0.0000000001, 0.000000000001): | |
print "X-Rays" | |
elif answerlamda <= 0.000000000001: | |
print "Gamma Rays" | |
else: | |
print "not an existing band" | |
elif choice > "2": | |
print "Input must be a 1 or a 2. Please Run the Program again." | |
# choice = raw_input() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment