Python Celsius to Fahrenheit

Write a program in Python to calculate the Fahrenheit of the following Celsius list by using Lambda function.

Suppose the Celsius lists are -

Celsius = [26.2, 33.2, 29.3, 32.4]

Solution

Such a type of program plays an important role in the most scientific applications, as it is the most widely used temperature scale throughout the world. The Fahrenheit scale is mostly used in the United States.

In the Celsius scale, the boiling point of water is 100°C, and the freezing point is at 0°C, while in the Fahrenheit scale the boiling point of water is measured at 212°F and freezing point at 32°F.

celsius * 1.8 = fahrenheit - 32

Lambda is an anonymous function that contains any number of arguments, but only one expression. This function is defined without a name.


Syntax of Python lambda()
lambda arguments: expression

Here, the arguments can be of any numbers, but the expression should be only one.





Python program to convert Celsius to Fahrenheit

This is the following solution to calculate the Fahrenheit of the following Celsius list by using Lambda function.

Celsius = [26.2, 33.2, 29.3, 32.4]
Fahrenheit = map(lambda x: (float(9)/5)*x + 32, Celsius)
print Fahrenheit

Output of the above code
Python map()

In the above code, we have used the map() function. It accepts the name of a function in the first parameter and the Celsius sequence in the second parameter. The map() applies the function to convert Celsius to Fahrenheit to all the elements of the Celsius sequence. It returns a new list with the elements changed by the function.







Related Articles

Python program to multiply two numbers
Count consonants in a string Python
Sum of n numbers in python using for loop
Python program to check leap year
Python program to sort words in alphabetical order
Python program for Prime Number
Odd Even Program in Python
Python program to convert Celsius to Fahrenheit
Python Convert XML to CSV
Python Text to Speech
Python send mail to multiple recipients using SMTP server
How to generate QR Code in Python using PyQRCode
Python programs to check Palindrome strings and numbers
CRUD operations in Python using MYSQL Connector
Fibonacci Series Program in Python
Python File Handler - Create, Read, Write, Access, Lock File
Python convert XML to JSON
Python convert xml to dict
Python convert dict to xml




Read more articles


General Knowledge



Learn Popular Language