Write a loop that runs from 0 to 20 and have it print out those values. These are the Celsius values. Run the script and fix any errors. Add a formula to the loop which converts a Celsius temperature into a Fahrenheit temperature. Make sure the result is an integer. Change the print statement so it prints both temperatures. Run the script and fix any errors. Add a tab or use the format function to the print statement so both temperatures will be aligned in vertical columns. Run the script and fix any errors. Add a print statements before the loop that prints the name of the temperatures and a line of dashes, -. Run the script and fix any errors.

Respuesta :

Answer:

Part 1:

  1. for i in range(0, 21):
  2.    print(i)

Part 2:

  1. for i in range(0, 21):
  2.    print(i,  int((i * 1.8) + 32))

Part 3:

  1. for i in range(0, 21):
  2.    print(i, '\t',  int((i * 1.8) + 32))

Part 4:

  1. print("Celcius\tFahrenheit")
  2. print("--------------------")
  3. for i in range(0, 21):
  4.    print(i, '\t',  int((i * 1.8) + 32))

Explanation:

In Part 1, create a for loop that will print the value i from 0 to 20 (21 is exclusive).

In Part 2, we can apply the formula to convert Celsius to Fahrenheit and print both Celsius and Fahrenheit value together.

In Part 3, we use "\t" to create a tab between Celcius and Fahrenheit values

In Part 4, we add print statements above the for loop to print the name of temperatures and a line of dashes. The output is as follows:

Celcius Fahrenheit

--------------------

0        32

1        33

2        35

3        37

4        39

5        41

6        42

7        44

8        46

9        48

10       50

11       51

12       53

13       55

14       57

15       59

16       60

17       62

18       64

19       66

20       68

Answer:

print("Celcius\tFahrenheit")

print("- - - - - - - - - -")

for degree_in_celcius in range(0,21):

   degree_in_fahrenheit = int(round((9 * degree_in_celcius) / 5 + 32))

   print(degree_in_celcius, "\t", degree_in_fahrenheit)

Explanation:

- Use two print statements to print the header and dashes

- Initialize a for loop ranging from 0 to 20

- Inside the loop, convert the degree to the Fahrenheit using formula

- Print the results