Conversion - Python Programming Exercise

In this exercise, you will develop a Python program that asks the user for a temperature in Celsius and converts it to both Kelvin and Fahrenheit. The program will use the formulas: Kelvin = Celsius + 273 and Fahrenheit = Celsius * 1.8 + 32. This task allows you to practice handling user input and performing unit conversions using basic arithmetic operations in Python. By completing this exercise, you will gain a deeper understanding of Python syntax and how to work with mathematical formulas. You will also enhance your skills in working with user input and displaying the results in a clear and informative way. This is a foundational skill for building more advanced Python programs that require mathematical calculations and data conversions.

 Category

Your First Steps in Python

 Exercise

Conversion

 Objective

Develop a Python program that asks the user for a temperature in Celsius and converts it to both Kelvin and Fahrenheit. Use the following formulas for conversion:

Kelvin = Celsius + 273
Fahrenheit = Celsius * 1.8 + 32

The program should then display the temperature in both Kelvin and Fahrenheit.

 Example Python Exercise

 Copy Python Code
# Prompt the user to enter a temperature in Celsius
celsius = float(input("Please enter a temperature in Celsius: "))

# Convert the temperature to Kelvin
kelvin = celsius + 273

# Convert the temperature to Fahrenheit
fahrenheit = celsius * 1.8 + 32

# Display the temperature in both Kelvin and Fahrenheit
print(f"The temperature in Kelvin is {kelvin}")
print(f"The temperature in Fahrenheit is {fahrenheit}")

 Output

Please enter a temperature in Celsius: 25
The temperature in Kelvin is 298.0
The temperature in Fahrenheit is 77.0

 Share this Python Exercise

 More Python Programming Exercises of Your First Steps in Python

Explore our set of Python Programming Exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of Python. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in Python.

  •  Initial interaction with Python

    In this exercise, you will develop a Python program to output "Hello" on the screen, followed by your name on a separate line. This exercise is perfect for pra...

  •  Addition of two values

    In this exercise, you will develop a Python program to print the result of adding 12 and 13 on the screen. This exercise is perfect for practicing basic arithm...

  •  Divide two values

    In this exercise, you will develop a Python program to display the result of dividing 24 by 5 on the screen. This exercise is perfect for practicing basic arit...

  •  Complex Calculations and Order of Operations

    In this exercise, you will develop a Python program to calculate and display the results of several mathematical operations. You will work with expressions such as 1 + 3 ...

  •  Variable-Based Multiplication

    In this exercise, you will develop a Python script to calculate and display the product of two numbers entered by the user. This task introduces you to handlin...

  •  Utilizing {0} and Adding Comments

    In this exercise, you will develop a Python program that prompts the user to input three numbers and then displays their product. The program should beg...