LAB Topic 1 F23

.docx

School

Texas A&M University *

*We aren’t endorsed by this school

Course

102

Subject

Computer Science

Date

Jan 9, 2024

Type

docx

Pages

3

Uploaded by ProfLightning103643

Lab: Topic 1 ENGR 102 – Fall 2023 Lab: Topic 1 Deliverables: This is an individual assignment, but you may consult your classmates and others as you work. You must submit your own code. Please submit the following files. I suggest testing it in your preferred IDE first to get the hang of things, then submit your working files to zyBooks . howdy_world.py print_math.py follow_directions.py Activity #1: Howdy World – individual Write a program named howdy_world.py that outputs: A) Howdy, World! B) One sentence giving some interesting fact about yourself Example output: Howdy, World! I code in python for fun. Activity #2: Print math – individual The purpose of this activity is to familiarize you with some basic engineering equations and provide practice writing a simple Python program that performs calculations and displays results. For the equations below, write code that will display the numerical result of using the equation with the specified inputs. Notice that the inputs have units associated with them and that you will need to interpret the result using the correct units. Please include comments in your code, as needed, to describe what your code is doing. Example : Let’s say we want to compute the area of a rectangle of length 5 inches and height 3 inches. The line of code below will print the numerical result. Code: print(5 * 3) Output: 15 If that is all we include in the code and in the output, it will be extremely difficult for someone to understand what the code does or to properly interpret the result. That someone may be the person grading your work, or may be you if you look back at this code in a few weeks! Note : The code includes the line print(5 * 3) and not print(15) . We want to use a mathematical expression inside the parentheses. You’ll understand why when we reuse this code in the next lab assignment. It’s good practice to use comments to document what your code is doing. You can also print out extra information to make the output more meaningful and easier to read. Based upon Dr. Keyser’s Original 1 Revised Fall 2023 SNR
Lab: Topic 1 New code: # Calculate/print the area of a rectangle of length 5 in # and height 3 in print("Area of rectangle is", 5 * 3, "in^2") New output: Area of rectangle is 15 in^2 In the new version of the code, the first comment simply describes what the line of code below it does. It is not printed to the screen. Next, three separate items of information are printed to the screen using one print() statement: 1. "Area of rectangle is" – a description of the output value 2. 5 * 3 – the result of the mathematical operation 3. "in^2" – another string that indicates the units Notice that these three items are separated by commas in the print() statement and that the “strings” consist of text enclosed inside double quotation marks. By default, when print items are separated by a comma, a space is inserted between the items when printed. If someone looks at this code and the output, they should be able to tell what you are doing without having to ask too many questions. Write a program named print_math.py to produce output for the following calculations: A) Calculate the force in Newtons applied to an object with mass 27 kg and acceleration 1.5 m/s^2. According to Newton’s Second Law the net force applied to an object produces a proportional acceleration. B) Calculate the wavelength of x-rays scattering from a crystal lattice with a distance between crystal layers of 0.025 nm, scattering angle of 35 degrees, and first order diffraction. Bragg’s Law describes the scattering of waves from a crystal using the equation = 2 d sin θ The standard unit of wavelength in the SI system is nanometers (nm). C) Calculate how much Radon-222 is left after 5 days of radioactive decay given an initial amount of 27 g and a half-life of 3.8 days. The equation for radioactive decay is N ( t ) = N 0 2 t / t 1 / 2 where N 0 is the intial amount (units of grams), t is the time (units of days), and t 1 / 2 is the half-life (units of days). D) Calculate the pressure of 5 moles of an ideal gas with a volume of 0.27 m^3, and temperature of 415 K. The Ideal Gas Law is the equation of state of a hypothetical ideal gas and is a good approximation of the behavior of gases under many conditions. Use a value of 8.314 m^3Pa/K·mol for the gas constant. The standard unit of pressure in the SI system is kilopascals (kPa). Example output: Force is 40.5 N Wavelength is 0.028678821817552304 nm Radon-222 left is 10.846051558652912 g Pressure is 63.89462962962962 kPa Activity #3: Follow directions – individual The purpose of this activity is to get you used to zyBooks, and to learn to follow directions. You will encounter limits of functions in calculus and learn to work with them analytically. Writing this program Based upon Dr. Keyser’s Original 2 Revised Fall 2023 SNR
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help