{"id":56,"date":"2008-01-03T18:25:10","date_gmt":"2008-01-03T23:25:10","guid":{"rendered":"http:\/\/blogs.cae.tntech.edu\/mwr\/python-for-fortran-programmers-chapter-2\/"},"modified":"2008-01-03T18:25:10","modified_gmt":"2008-01-03T23:25:10","slug":"python-for-fortran-programmers-chapter-2","status":"publish","type":"page","link":"https:\/\/sites.tntech.edu\/renfro\/python-for-fortran-programmers\/python-for-fortran-programmers-chapter-2\/","title":{"rendered":"Python for Fortran Programmers &#8211; Chapter 2"},"content":{"rendered":"<p><a href=\"..\/\">See the index page for context<\/a>.<\/p>\n<hr>\n<pre>\n#!\/usr\/bin\/python\n\n# Translation of program \"CONVRT\" from D.M. Etter, _Structured FORTRAN\n# 77 for Engineers and Scientists_, p.46\n\n# This program converts kilowatt-hours to Joules.\n\nkwh = float(raw_input(\"Enter energy in kilowatt-hours: \"))\njoules = 3.6e6*kwh\n\nprint \"%6.2f kilowatt-hours is %9.2e Joules\" % (kwh, joules)\n\n# Notes:\n#\n# 1. raw_input reads keyboard input as a string. float(somestring)\n# converts somestring into a floating-point representation. Similarly,\n# int(somestring) converts somestring into an integer representation\n# and long(somestring) converts somestring into a long integer\n# representation.\n#\n# 2. Etter's text shows 0.20e+08 Joules as the result, when 1.98e+07\n# is actually correct. Real variables must have been much lower\n# precision in the original text.\n<\/pre>\n<hr>\n<pre>\n#!\/usr\/bin\/python\n\n# Translation of program \"GROWTH\" from D.M. Etter, _Structured FORTRAN\n# 77 for Engineers and Scientists_, p.49\n\n# This program predicts bacterial growth\n\nfrom math import exp\n\nyold = float(raw_input(\"Enter initial population: \"))\ntime = float(raw_input(\"Enter time elapsed in hours: \"))\n\nynew = yold*exp(1.386*time)\n\nprint \"Initial population = %9.4f\" % (yold)\nprint \"Time elapsed (hours) = %9.4f\" % (time)\nprint \"Predicted population = %9.4f\" % (ynew)\n\n# Notes:\n#\n# Any math beyond the most basic operations (addition, subtraction,\n# multiplication, division) requires the math module to be\n# available. You can either use the form 'from math import exp, log,\n# log10, pow, ...' to import specific functions from the math module\n# and call them by name as 'exp', 'log', etc. , or the form 'import\n# math' to import the entire module, and call them as 'math.exp',\n# 'math.log', etc.\n#\n# Option 1:\n#\n# from math import exp\n# ...\n# ynew = yold*exp(1.386*time)\n#\n# Option 2:\n#\n# import math\n# ...\n# ynew = yold*math.exp(1.386*time)\n#\n# See http:\/\/docs.python.org\/lib\/module-math.html for other functions.\n<\/pre>\n<hr>\n<pre>\n#!\/usr\/bin\/python\n\n# Translation of program \"DATE\" from D.M. Etter, _Structured FORTRAN\n# 77 for Engineers and Scientists_, p.51\n\n# This program estimates the age of an artifact from the proportion of\n# carbon remaining in the artifact.\n\nfrom math import log\n\ncarbon = float(raw_input(\"Enter proportion remaining for carbon dating: \"))\n\nage = (-log(carbon))\/0.0001216\n\nprint \"Estimated age of artifact is = %6.1f years\" % (age)\n<\/pre>\n<hr>\n<pre>\n#!\/usr\/bin\/python\n\n# Translation of program \"TRAIN\" from D.M. Etter, _Structured FORTRAN\n# 77 for Engineers and Scientists_, p.53\n\n# This program computes the horizontal force generated by a train on a\n# level curve.\n\nfrom math import pow\n\nweight = float(raw_input(\"Enter weight of train in tons: \"))\nmph = float(raw_input(\"Enter speed of train in miles per hour: \"))\nradius = float(raw_input(\"Enter radius of curve in feet: \"))\n\nforce = (weight*2000.0\/32.0)*(pow((mph*1.4667),2)\/radius)\n\nprint \"Train weight - %8.2f tons\" % (weight)\nprint \"Train speed - %8.2f mph\" % (mph)\nprint \"Curve radius - %8.2f feet\" % (radius)\nprint\nprint \"Resulting horizontal force - %8.2f pounds\" % (force)\n<\/pre>\n<hr>\n<pre>\n#!\/usr\/bin\/python\n\n# Translation of program \"RELY\" from D.M. Etter, _Structured FORTRAN\n# 77 for Engineers and Scientists_, p.57\n\n# This program computes the reliability of instrumentation using a\n# Bernoulli equation.\n\nfrom math import pow\n\nprint \"Enter reliability of single component\"\np = float(raw_input(\"(Use percentage between 0.0 and 100.0): \"))\n\nn = int(raw_input(\"Enter number of components in equipment: \"))\n\nperc = pow((p\/100.0),n)*100.0\n\nprint \"Percent of the time that the equipment\"\nprint \"should work without failure is %6.2f%%\" % (perc)\n\n# Notes:\n#\n# See\n# http:\/\/docs.python.org\/lib\/typesseq-strings.html#typesseq-strings\n# for more information on formatting strings in Python.\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>See the index page for context. #!\/usr\/bin\/python # Translation of program &#8220;CONVRT&#8221; from D.M. Etter, _Structured FORTRAN # 77 for Engineers and Scientists_, p.46 # This program converts kilowatt-hours to Joules. kwh = float(raw_input(&#8220;Enter energy in kilowatt-hours: &#8220;)) joules = 3.6e6*kwh print &#8220;%6.2f kilowatt-hours is %9.2e Joules&#8221; % (kwh, joules) # Notes: # # 1. &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/sites.tntech.edu\/renfro\/python-for-fortran-programmers\/python-for-fortran-programmers-chapter-2\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Python for Fortran Programmers &#8211; Chapter 2&#8221;<\/span><\/a><\/p>\n","protected":false},"author":87,"featured_media":0,"parent":55,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-56","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/pages\/56","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/users\/87"}],"replies":[{"embeddable":true,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/comments?post=56"}],"version-history":[{"count":0,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/pages\/56\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/pages\/55"}],"wp:attachment":[{"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/media?parent=56"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}