python temperature conversion Fahrenheit temperature realization code

  • 2021-08-12 03:11:58
  • OfStack

I believe that some small partners are definitely prepared before they come into contact with py, and they have wanted to learn languages for a long time. Take this site as an example, 1 will take advantage of the gap to start looking for courses to learn, write down the learning process, and ask some big brothers questions. In this way, I can get the answer to the question and hear other people's summary knowledge, which is much more flexible than learning the textbook content directly. Everyone can also be like this site. Let's start talking about the first programming problem, the temperature problem.

The code for converting temperature to Fahrenheit temperature is as follows:


Tempstr=input(" Please enter the temperature value to be converted :")
if Tempstr[-1] in ['F','f']:
C=(eval(Tempstr[0:-1])-32)/1.8
print(" The converted temperature value is  {:.2f}C".format(C))
elif Tempstr[-1] in ['C','c']:
F=1.8*eval(Tempstr[0:-1])+32
print(" The converted temperature value is {:.2f}F".format(F))
else:
print(" Output temperature symbol error ")

Python Implementation of Simple Temperature Conversion Extension Example


TempStr=input(" Please enter a temperature value with a sign, C/c Represents degrees Celsius, F/f Indicates the temperature in Fahrenheit: ")
if TempStr[-1] in ['F','f']:
  C=(eval(TempStr[0:-1])-32)/1.8
  print(" The converted temperature is {:.2f}C".format(C))
elif TempStr[-1] in ['C','c']:
  F=1.8*eval(TempStr[0:-1])+32
  print(" The converted temperature is {:.2f}F".format(F))
else:print(" Wrong input format ")
'''
1 The format framework of the program 
python There are strict indentation requirements, and incorrect programs will run incorrectly; Indent expresses the format framework of the program, and expresses the only inclusion and hierarchical relationship between codes 1 Means; Length 1 To.  
2 Naming and reserved words 
 Variable: A placeholder used to hold and represent data. Variables are represented by identifiers, and the process of associating identifiers is called naming. You can use equal signs to assign or modify values to vectors  = Assignment symbol 
 Reserved word / Keyword: 33 Reserved words   Identifiers defined internally by the programming language and reserved for use 
3 , data type 
4 Statements and functions 
5 , python Input and output of program 
'''


Related articles: