Python Celsius to Fahrenheit
The following example demonstrates how to convert Celsius to Fahrenheit:
# -*- coding: UTF-8 -*- # Filename : test.py # author by : www.w3cschool.cn # User input temperature in Celsius # Receive user income celsius = float(input('Enter temperature in Celsius: ')) # Calculate temperature in Fahrenheit Fahrenheit = (celsius * 1.8) + 32 print('%0.1f Celsius to Fahrenheit is %0.1f' %(celsius,fahrenheit))
The output of executing the above code is:
Enter temperature in Celsius: 38 38.0 Celsius to Fahrenheit is 100.4
In the above example, the formula for converting Celsius to Fahrenheit is celsius * 1.8 = fahrenheit - 32. So get the following formula:
centigrade = (Fahrenheit - 32) / 1.8
Python3 os.rename() method
overview
The os.rename() method is used to name a file or directory from src to dst, if dst is an existing directory, OSError will be thrown.
grammar
The syntax of the rename() method is as follows:
os.rename(src, dst)
parameter
-
src -- directory name to modify
-
dst -- the modified directory name
return value
The method has no return value
example
The following example demonstrates the use of the rename() method:
#!/usr/bin/python3 import os, sys # list directories print ("The directory is: %s" %os.listdir(os.getcwd())) # double naming os.rename("test","test2") print ("Renamed successfully.") # List the renamed directory print ("The directory is: %s" %os.listdir(os.getcwd()))
The output of executing the above program is:
The directory is: [ 'a1.txt','resume.doc','a3.py','test' ] Renaming succeeded. [ 'a1.txt','resume.doc','a3.py','test2' ]