Chapter 2 Output -10 Fahrenheit - Celsius conversion table (15 minutes)

Enter two positive integers lower and upper (lower≤upper≤100), make an output range of [lower, upper], and increments of 2 ° F Fahrenheit - Celsius conversion table.

Temperature conversion formula: C = 5 × (F-32) / 9, wherein: C represents temperature in degrees Celsius, F represents Fahrenheit.

Input format:
input two integers in a row, each value representing the lower and upper, separated by spaces.

Output format:
The first line of output: "fahr celsius"

Then each row outputs a Fahr Fahrenheit (integer) and a Celsius Celsius (6 characters occupying width, right justified, Reserved 1 decimal).

If the range entered is not valid, the output "Invalid.".

Input Example 1:
3235

Sample Output. 1:
Fahr Celsius
32 0.0
34 is 1.1

Input Sample 2:
40 30

Output Sample 2:
Invalid.

lower,upper=input().split()
lower=int(lower)
upper=int(upper)
if lower>upper:
    print("Invalid.")
else:
    print("fahr celsius")
    for i in range(lower,upper+1,2):
        n=5*(i-32)/9
        print("{:d}{:>6.1f}".format(i,n))
Published 14 original articles · won praise 1 · views 89

Guess you like

Origin blog.csdn.net/weixin_45948920/article/details/104345776
Recommended