Skip to content

Instantly share code, notes, and snippets.

@liamlah
Created February 9, 2012 04:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liamlah/1777279 to your computer and use it in GitHub Desktop.
Save liamlah/1777279 to your computer and use it in GitHub Desktop.
Python Frequency/wavelength converter
print "This script can convert wavelengths to frequencies or vice versa."
sol = 299792458.00 #this is the speed of light in m/s
#ol = 300000000.00 #this is the speed of light in m/s
def wavelength():
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:
print "Theoretically long Radio wave"
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 within a range generally observed"
def frequency():
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 "Theoretically long Radio wave"
if answerlamda <= 1000 and answerlamda >= 0.01:
print "Radio Wave"
elif answerlamda <= 0.01 and answerlamda >= 0.00001:
print "Microwave"
elif answerlamda <= 0.00001 and answerlamda >= 0.0000005:
print "Infra Red"
elif answerlamda <= 0.0000005 and answerlamda >= 0.00000001:
print "Visible Light"
elif answerlamda <= 0.00000001 and answerlamda >= 0.0000000001:
print "Ultra Violet"
elif answerlamda <= 0.0000000001 and answerlamda >= 0.000000000001:
print "X-Rays"
elif answerlamda <= 0.000000000001:
print "Gamma Rays"
else:
print "Not within a range generally observed"
#def frequency():
# 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"
choice_options = {
1: wavelength,
2: frequency,
}
choice = 0
while choice not in choice_options:
print "do you have (1) a wavelength, or (2) a frequency?"
choice = int(raw_input())
choice_options[choice]()
#next need to do defs
#you should bind the band calcs to a def, if answerlamda == lamdaband try i the def "if band == range print microwave
# you can ask what unit they want to use and you should be able to change the value for SOL to create the appropriate output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment