### Question 1

The purpose of this question is to write a complete Python program that computes the Black Body Radiation emitted by an object for a given temperature in degrees Celsius. The human eye cannot see Black Body Radiation, but it can be detected and enhanced by electronic devices such as night vision goggles.

Write a complete Python program that inputs a temperature in degrees Celsius and computes the corresponding Black Body Radiation. The formulae for computing the values of the wavelengths and radiations require the temperatures be in degrees Kelvin, where degrees Kelvin = degrees Celsius + 273.15.

You will use the following constants in the formulae:

• Planck’s constant h = 6.6260695×10-34 m²kg/s

• Speed of light in a vacuum c = 299792458 m/s

• Boltzmann constant k = 1.3806488×10-23 m²kg/(s²K)

• Wien’s constant for peak wavelength = 2.8977721×10-³

Peak wavelength = 2.8977721×10-3 / T, where T is the temperature in degrees Kelvin.

Frequency v = c / wavelength

Display the heading as shown in the sample run of the program. Display the temperature in degrees Celsius in 14 character positions to 2 decimal places, the wavelength in meters, the frequency in hertz and the radiation in 14 character positions to 7 decimal places using exponential format. Separate each of these by 2 spaces.

A sample run of the program is shown below

———————————————————–

Enter the body temperature in degrees Celsius: 37.25

Celsius Wavelength Frequency Peak

Temperature in meters in Hertz Radiation

————– ————– ————- ————–

37.25 9.3356060e-06 3.2112801e+13 3.4308221e-12

Programmed by Stew Dent.

Date: Thu Dec 10 13:56:06 2015

End of processing.

Hand in your complete program

### Question 2

Equation 1 gives one of Cardano’s formulae for computing the value of x for the equation x³ = cx + d.

Equation 1

Equation 2 specifies the value of e.

Equation 2

Notice that e can be negative if the value of d is large enough compared to the value of c, in which case x will be a complex number.

Write a complete Python program that computes the value of x for the equation x3 = cx + d. Use input to read in the value of c as a float. Loop as long as c is greater than zero. In the loop:

• Use input to read in the value of d as a float.

• Use equations 2 and 1 to compute the values of e and x.

• Compute the values of x3 and cx+d.

• Display the values of , x, x3 equal to cx+d, the imaginary part of x, x3 and cx+d as shown in the sample run of the program. Use %r as the format code for all of these

Display the termination message that includes your name and the date and time the program was run. A sample run of the program is shown on the next page. The values for , x3 equal to cx+d and the imaginary part of x have been included in the output to get a better appreciation of what is happening inside the program. What do you notice about the imaginary part of x?

A sample run of the program follows. Your input and output should match the sample as closely as possible. In the last two examples a line of output has been wrapped to fit within the boundaries of this document. On the screen there should be three lines of output for each test case.

———————————————————————————————————————————-

For x^3 = cx+d enter the value of c (> 0): 15

For x^3 = cx+d enter the value of d: 4

sqrt(e)=11j, x=4.0, (x**3 == c*x+d)=True, imag=0.0

x**3=64.0

c*x+d=64.0

For x^3 = cx+d enter the value of c (> 0): 2

For x^3 = cx+d enter the value of d: 16

sqrt(e)=(7.981459998252431+0j), x=2.7835375444710575, (x**3 ==

c*x+d)=False, imag=0.0

x**3=21.567075088942154

c*x+d=21.567075088942115

For x^3 = cx+d enter the value of c (> 0): 12

For x^3 = cx+d enter the value of d: 2

sqrt(e)=7.937253933193772j, x=3.5446068153161496, (x**3 ==

c*x+d)=True, imag=0.0

x**3=44.53528178379379

c*x+d=44.53528178379379

For x^3 = cx+d enter the value of c (> 0): 0

Programmed by Stew Dent.

Date: Thu Dec 10 11:44:37 2015

End of processing.

Challenge:

• Why isn’t x³ equal to cx+d for every combination of values for c and d?

• Write your answer as a comment in the program.

### Question 3

The purpose of this question is to write a complete Python program that computes the approximate value π, using the series in the equation given below.

Add terms to the sum of the series as long as the absolute value of the current term is greater than the given tolerance. Count the number of terms in the series.

Your program must input the value of the tolerance as a float.

Display Python’s value of π and the sum of the series to 14 decimal places.

Compute the absolute value of the difference between the value of the sum of the series and Python’s value of π. This value must be displayed to 6 decimal places using the exponential format and is referred to as the error in the approximation.

Display the number of terms in the series as an integer.

A sample run of the program for a tolerance of 10-17 is shown below. The output from your program must match the output shown below as closely as possible.

Enter the tolerance: 1e-17

The approximate value of pi is 3.14159265358979

Python’s value of pi is 3.14159265358979

The error in the approximation of pi is 8.881784e-16

The number of terms used to calculate the value of pi is 32

Programmed by Stew Dent.

Date: Mon Dec 14 09:57:21 2015

End of processing.

### Question 4

The purpose of this question is to write a program that computes the approximate value ex to any number of decimal places, using the infinite series in equation 1 given below.

Equation 1

Add terms to the sum of the series as long as the absolute value of the current term is greater than zero. Count the number of terms in the series.

You must use only integers to compute the sum of the series. The program must input x as an integer, and the number of decimal places to which ex is to displayed as an integer.

A sample run of the program follows. Your output should match the sample output as closely as possible

Enter the number of decimal places: 50

Enter the power of e: 3

Python’s value of e to the power 3 is:

20.085536923187668

e to power 3 to 50 decimal places is:

20.08553692318766774092852965458171789698790783855415

The number of terms in the series is 61

Programmed by Stew Dent

Date: Mon Dec 14 10:11:43 2015

End of processing.

Test your program for different values of x and different numbers of decimal places. Hand in your program.

## Reviews

There are no reviews yet.