'Temperature conversion fahrenheit to celsius vice versa python

Hi I'm trying to make a program that takes as many values in celsius or fahrenheit and puts them in a list and converts them to the other value then displays the output. I'm getting stuck at applying the formula for fahrenheit to celsius to the list. Here's my code.

if temp == "F":
input_string = input('Enter Fahrenheit values for conversion to celsius separated by space ')
print("\n")
my_list = input_string.split()
print('list:', my_list)
for i in range(len(my_list)):
    my_list[i] = int(my_list[i])
    print("These temperatures in Celsius are...: ", (x - 32) * 5/9 for x in [my_list],)


Solution 1:[1]

You are not missing a whole lot, pretty much just some syntax mistakes. You also do not need a whole loop just to type cast upon doing the initial operation.

if temp == "F":
    input_string = input('Enter Fahrenheit values for conversion to Celsius separated by space ')
print("\n")
my_list = input_string.split()
print('list:', my_list)

print("These temperatures in Celsius are...: ", [(int(x) - 32) * 5/9 for x in my_list])

Just make sure that you have the list comp statement all encapsulated and don't put the list in square brackets. You could also do a round(value, 2) if you want to just get the degree to 2 decimal places

To round the values just write the comprehension like this

[round((int(x) - 32) * 5/9, 2)  for x in my_list]

Solution 2:[2]

For anyone doing the text book assignment:

i = 0
c = i 

for i in range(0,101):
    f=(1.8*c)+32
    c=i+1
    print("Celsius","is",i, "Fahrenheit is", f)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ConnerWithAnE
Solution 2 Danie