Python Celsius to Fahrenheit, Python3 os.rename() method

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 Celsius temperature 

# Receive user income 
celsius = float(input('Enter Celsius temperature: ')) 

# Calculate Fahrenheit temperature 
fahrenheit = (celsius * 1.8) + 32 
print('%0.1f Celsius temperature converted 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 directory 
print ("The directory is: %s" %os.listdir(os.getcwd())) 

# Rename 
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' ] 
Renamed successfully. 
['a1.txt','resume.doc','a3.py','test2']

Guess you like

Origin blog.csdn.net/m0_67373485/article/details/130038222
Recommended