Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you type out my python code in python 3 to where it does not run a continuous loop on the while statement and also

Can you type out my python code in python 3 to where it does not run a continuous loop on the while statement and also prompts the user if they want to enter more data, then prints it all in the end as a neat list at the end. import math from tabulate import tabulate mass = [] damping = [] stiffness = [] natural_frequency = [] damping_ratio = [] response = [] table = [] # initially choice variable is set to yes ch = 'yes' while (ch == 'yes'): m = float(input('Mass in kg: ')) mass.append(m) c = float(input('Damping in N/(m/s): ')) damping.append(c) k = float(input('Stiffness in N/m: ')) stiffness.append(k) # Calculate w, natural frequency(nf), damping ratio(dr) according to given formula w = math.sqrt(k / m); nf = w / (2 * 3.14) dr = (c / (2.0 * (math.sqrt(k * m)))) # store natural frequency and damping ratio in the list natural_frequency.append(nf) damping_ratio.append(dr) # update the value of system response according to damping ratio r = '' if (dr == 0): r = 'Undamped' elif (dr < 1 and dr > 0): r = 'Underdamped' elif (dr == 1): r = 'Critically Damped' elif (dr > 1): r = 'Overdamped' response.append(r) print('Natural Frequency: ', '%.4f' % nf, end=' ') print('Damping Ratio: ', '%.4f' % dr, end=' ') # a 2D list, table is maintainted for the tabulate function data = [m, k, c, nf, dr, r] table.append(data) ch = input(' Enter yes to continue, no to exit. ') # tabulate function is provided with data, table header, and the formatting of float data type print(tabulate(table, headers=['Mass kg', 'Stiffness N/m', 'Damping N/(m/s)', 'Omega_n Hz', 'Zeta', 'Response Type'], floatfmt=".4f")) 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions