Skip to content

tamu-edu-students/engr-102-lab-3-individual

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

ENGR 102 Lab Topic 3 (individual)

Activities

This lab consists of two individual activities, and an optional bonus activity. Please submit the following files to Gradescope. Check out the Frequently Asked Questions below. Please include the individual header in your ~.py files.

  1. Using Input
  2. Calling Functions
  3. Challenge Program (Optional)

Using Input

Convert your program from individual Lab: Topic 2 Activity #1 (Using Variables) to a new program that produces identical output. However, your new program should take in input from the user as appropriate, store values in variables, and output in the required format. Please name the program using_input.py.

Produce output for the following calculations:

  1. Calculate the Reynolds Number (Re) for a fluid with a given velocity in m/s, a given characteristic linear dimension in m, and a given viscosity in m^2/s. Display the result with zero (0) decimal places.
  2. Calculate the wavelength of x-rays scattering from a crystal lattice with a given distance between crystal layers in nm and a given scattering angle in degrees. Assume first order diffraction. Display the result with four (4) decimal places. (See Bragg’s Law from before)
  3. Use the Arps equation to calculate the production rate of a well given a time in days, an initial production rate in barrels/day, an initial decline rate in 1/day, and a hyperbolic constant of 0.8. Display the result with two (2) decimal places.
  4. Use the Tsiolkovsky rocket equation to calculate the change of velocity of an object with a given initial mass in kg, a given final mass in kg, and a given exhaust velocity in m/s. Display the result with one (1) decimal places.

Each part of your program should perform the following tasks:

  • Print what the part of the program does to the screen.
  • Prompt the user to enter required data from the keyboard. Include proper units in the prompt as shown in the example output below.
  • Get the inputs from the user and store in appropriately named variables.
  • Perform the necessary calculations.
  • Output the result to the screen with proper labels and units.

Example output (using inputs 9, 0.875, 0.0015, 0.025, and 35):

This program calculates the Reynolds number given velocity, length, and viscosity
Please enter the velocity (m/s): 9
Please enter the length (m): 0.875
Please enter the viscosity (m^2/s): 0.0015
Reynolds number is 5250

This program calculates the wavelength given distance and angle
Please enter the distance (nm): 0.025
Please enter the angle (degrees): 35
Wavelength is 0.0287 nm

Please see the tests on Gradescope for exact wording for the remaining parts. As always, please include descriptive comments in your code so that someone may follow your programming logic.

Calling Functions

This activity provides practice for writing programs to perform multiple complex calculations, and to give you practice calling basic functions.

Starting with the template provided here, write a program that calculates the area of several regular polygons when given a side length. Your program should take as input from the user a value for side length and calculate the following values:

  • The area of an equilateral triangle
  • The area of a square
  • The area of a regular pentagon
  • The area of a regular hexagon
  • The area of a regular dodecagon (12 sides)

We’re going to ignore units for this problem. The template provided contains the function printresult(). You should NOT modify the function in your code, nor should you write your own function. Instead, have your program calculate the area for each shape and then call the provided function to generate the output according to the example shown below. Use two (2) decimal places for the side length and three (3) for the area. Name your program calling_functions.py.

Before you beginning coding, you should stop and think briefly about how you want to structure your program. This activity is a great way to practice calling the same function multiple times.

Example output (using input 1.25):

Please enter the side length: 1.25
A triangle with side 1.25 has area 0.677
A square with side 1.25 has area 1.562
A pentagon with side 1.25 has area 2.688
A hexagon with side 1.25 has area 4.059
A dodecagon with side 1.25 has area 17.494

Helpful Hint: When testing/debugging a program that requires input from the keyboard, it can be quite frustrating to have to retype the input every time you want to run the program. One technique for dealing with this problem is to simply “hard code” the variable values during the debugging process (assign variable values in the code rather that retrieving values from the keyboard), then add the code to retrieve the input from the keyboard after you are sure the code works.

Challenge Program (Optional)

Using only the commands we have covered in class so far, write a program that asks a user for a number of digits, and prints the number τ (tau) rounded to that many digits of precision. Do NOT use the round() function. Instead, get creative and think of another way!

Example output (using input 5):

Please enter the number of digits of precision for tau: 5
The value of tau to 5 digits is: 6.28319

If you complete this challenge correctly, you will receive 2 bonus points on this assignment. Please name your program tau_challenge.py and submit to Gradescope.

Frequently Asked Questions

  1. How do I round my output again? Use string formatting (not the round() function!) to specify how many digits to display. Watch this video for examples.

  2. Do I have to use radians in my trig functions every time? YES! Every. Single. Time. Have python convert for you! Example: sin(angle * pi / 180)

  3. I'm still having trouble figuring out why my output is wrong. Help? Click on the failed test. You should see a caret (^) indicating what's different between your output and the solution output. Did you misspell something? Math error? Incorrect formatting? Hopefully that helps you figure it out!

  4. Challenge activity how do I do it without round()? If I gave you the answer it wouldn't be a challenge, would it? :) There's more than one way to solve it. One method: get creative with math operators. Remember some of the new ones we talked about in lecture 1? Another method: we use string formatting to control how many digits to display. But instead of hardcoding a number, can you use a variable to construct the format string?

Have a question you don't see here? Email your instructor!

Based upon Dr. Keyser’s Original
Revised Summer 2025 SNR

About

Lab 3 individual

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages