0% found this document useful (0 votes)
109 views4 pages

Fahrenheit to Celsius Conversion in Python

The document is an experiment report that aims to: 1. Convert temperature readings from Fahrenheit to Celsius using the formula C = (5/9)*(F-32). 2. Test the Python program with input values of 68, 150, 212, 0, -22, -200 degrees Fahrenheit. 3. Discuss variable declaration, type casting, string formatting, and the steps taken to create the program.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
109 views4 pages

Fahrenheit to Celsius Conversion in Python

The document is an experiment report that aims to: 1. Convert temperature readings from Fahrenheit to Celsius using the formula C = (5/9)*(F-32). 2. Test the Python program with input values of 68, 150, 212, 0, -22, -200 degrees Fahrenheit. 3. Discuss variable declaration, type casting, string formatting, and the steps taken to create the program.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CHITTAGONG UNIVERSITY OF

ENGINEERING AND TECHNOLOGY

Department of Urban and Regional Planning


Course Name: Programming for Planners
Course ID: CSE 282

Experiment No. Experiment Title


01 Convert a temperature reading in degrees
Fahrenheit to degrees Celsius, using the formula
C = (5/9)* (F- 32).

Name: Norin Binte Khorshed Megha


Student ID: 2005028
Level: 2
Term: II
Date of Submission: 4th September, 2023
Marks:
Title:

Convert a temperature reading in degrees Fahrenheit to degrees Celsius, using the formula C
= (5/9)* (F- 32) Test the program with the following values: 68, 150, 212, 0, -22, -200 (degrees
in Fahrenheit).

Objective:

1. To learn about data type, variable and constant in Python.


2. To apply the mathematical operations for solving complex problems.
3. To understand the methods of variable declaration, type casting {conversion using str(),
int(),float()} and string formatting.

Introduction:

Python is a high-level, interpreted programming language known for its simplicity and
readability. It is used for a wide range of applications, including web development, data
analysis, machine learning, scientific computing, automation, and more. It supports all of the
math operations that one can expect. The basic ones are addition, subtraction, multiplication,
and division

If we want to convert temperature reading from Fahrenheit to Celsius, we need to use some
basic mathematical operations like subtraction (-), multiplication (*), and division (/).
Generally, the first step is variable declaration which refers to process of defining a variable
and specifying its data type. Type casting or type conversion is also used. It refers to the process
of changing the data type of a variable or an expression from one type to another. Then we use,
string formatting. It is the process of creating strings with placeholders that can be replaced
with values.

Discussion:

To convert temperature reading from Fahrenheit to Celsius, we need to input a variable (F) for
Fahrenheit reading. It is a variable and it must be an integer. Here users can put their desire
number which they want to convert. Then we need to convert the data to integer because input
function considers data as string automatically. We will type a formula for converting the

1
temperature from Fahrenheit to Celsius next. The formula is C= ((5/9)*(F-32)). So, it is
predefined by the coder. We will test the program with the following values: 68, 150, 212, 0,
-22, -200 (degrees Fahrenheit). After putting the integer value and running the code, the desire
Celsius value will come.

Source Code and Output:

For source code, we need to take F (Fahrenheit) using input function where any value can be
given. We had previously taken some values like 68, 150, 212, 0, -22, and -200 (Degrees
Fahrenheit). Now we will enter these values respectively. There an example is shown with 68-
degree Fahrenheit. Then we need to do type casting and write the formula for conversion.

The output will come with a value of Celsius. After testing one value we will test other values
respectively. For 68 degree Fahrenheit, we got 20 degree Celsius.

2
Conclusion:

Python is renowned for being easy to read and understand. Both novice and seasoned
programmers favor Python because of its adaptability, simplicity of learning, and robust
ecosystem. But a coder can face some challenges like:

 It is important to follow some basic rules of coding like using brackets, using inverted
coma (“”) in appropriate place, using numeric and string values perfectly.
 The length should not be normally more than 8 characters.
 It should not be a keyword, but keyword can be a part of variable, such as int_type
could be a variable, but int couldn't function in that way.
 Python is case sensitive thus uppercase and lowercase are significant. F and f will not
be same variable.
 White spaces should be avoided.

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

Common questions

Powered by AI

Python’s simple syntax and clear structure make it accessible to learners, allowing them to focus on programming concepts rather than cumbersome syntax. Its readability facilitates understanding and debugging, making it ideal for educational tasks such as temperature conversions, where the focus is on understanding data manipulation and program logic .

Proper variable naming enhances code clarity and maintainability by making the code self-explanatory. Avoiding keywords prevents errors, as keywords have predefined meanings in Python. In programming for planners, clear variable names and avoiding keywords are important for tracking variables' roles and ensuring code logic is not compromised .

String formatting is crucial as it enables dynamic output generation by inserting calculated values into a predefined template. For temperature conversion, formatted outputs ensure the results are presented clearly and readably, which helps in verifying correctness and improves the user interface aspect of the application .

The steps include defining a variable for the Fahrenheit temperature, using input to obtain this value, and applying the conversion formula C = (5/9)*(F-32). Type casting is crucial because the input function returns data as a string by default, which must be converted to an integer or float to perform arithmetic operations accurately .

Challenges include ensuring correct data types through type casting, managing Python's case sensitivity, correctly using mathematical operations and syntax such as brackets, and avoiding white space errors. Addressing these involves careful attention to coding conventions, testing, and validating inputs to ensure they conform to expected data types and formats .

Type casting allows variables to be converted into appropriate formats for specific operations. It ensures numerical data input as strings is converted to integers or floats, facilitating arithmetic operations needed for data conversion processes like temperature conversion, enhancing usability and ensuring accurate results .

In Python, data types, variables, and constants allow for structured and clear coding practices. Variables store data that can be manipulated, while constants provide values that do not change. In temperature conversion, using an integer or float data type for the Fahrenheit variable ensures mathematical operations can be accurately performed using the conversion formula C = (5/9)*(F-32). This aids in precise calculations essential for tasks like converting temperatures, where accurate results are required .

The conversion formula C = (5/9)*(F-32) uses subtraction, multiplication, and division, demonstrating Python’s ability to handle basic arithmetic operations. These operations are fundamental programming concepts enabling data manipulation, essential for tasks ranging from simple calculations to complex algorithms, showcasing Python’s broad utility in computational problem-solving .

Python's case sensitivity requires consistent naming conventions, meaning variables such as 'F' for Fahrenheit must be referenced in the same capitalization format throughout the code. This prevents errors where 'F' may be interpreted differently than 'f', which could lead to incorrect calculations or runtime errors during temperature conversion .

White spaces in Python are significant because they define code blocks and indentation. Mismanagement can lead to indentation errors or logical errors where code does not execute as intended. Proper management is crucial for maintaining program structure and flow, especially in conditionals and loops, which impact tasks such as temperature conversion .

You might also like