Python realizes system conversion (currency temperature length)

  • 2021-07-18 08:29:40
  • OfStack

RMB and US dollar are one of the two currencies commonly used in the world. Write a program for currency value conversion between currencies, among which:

The exchange rate between RMB and US dollar is fixed at US $1 = RMB 6.78.

The program can accept RMB or USD input and convert it into USD or RMB output. RMB is expressed in RMB, US dollar is expressed in USD, and there is no space between symbols and values

Example 1: RMB123

Example 2: USD20


TempStr = input()
if TempStr[0:3] in ['RMB']:
  C = eval(TempStr[3:])/6.78
  print("USD{:.2f}".format(C))
elif TempStr[0:3] in['USD']:
  F = 6.78*eval(TempStr[3:])
  print("RMB{:.2f}".format(F))

Temperature is characterized by two different systems: Celsius (Celsius) and Fahrenheit (Fabrenheit).

Write a program that converts the user's input of degrees Fahrenheit to degrees Celsius, or converts the input of degrees Celsius to degrees Fahrenheit.

The conversion algorithm is as follows: (C for degrees Celsius, F for degrees Fahrenheit)

C = ( F - 32 ) / 1.8

F = C * 1.8 + 32

The requirements are as follows:

(1) The degree Celsius of input and output starts with the capital letter C, and the temperature can be an integer or decimal, for example, C12.34 means 12.34 degrees Celsius;

(2) The Fahrenheit of input and output begins with the capital letter F, and the temperature can be an integer or decimal, for example, F87.65 means 87.65 degrees Celsius;

Example 1: C12.34

Example 2: F87.65


TempStr = input()
if TempStr[0] in['f','F']:
  C = (eval(TempStr[1:])-32)/1.8
  print("C{:.2f}".format(C))
elif TempStr[0] in['C','c']:
  F = 1.8*eval(TempStr[1:])+32
  print("F{:.2f}".format(F))

Write a program to calculate the 0 power to 5 power results of the input number N, and output these 6 results in turn, with spaces separating the output results. Where: N is an integer or floating point number.


b = input()
if '.' in b:
  b = float(b)
else :
  b = int(b)
print(b**0 ,b**1 ,b**2 ,b**3 ,b**4 ,b**5)

Using the turtle library, draw a square.


from turtle import *
color('black','white')
begin_fill()
for i in range(4):
  fd(100)
  rt(-90)
end_fill()
done()

Using turtle library, draw a 6-sided shape.


from turtle import *
color('black','white')
begin_fill()
for i in range(6):
  fd(100)
  rt(-60)
end_fill()
done()

To complete the length conversion between meters and inches, the basic requirements are as follows:

Enter inches and convert them into meters;

Enter meters and convert them to inches.

Inches are marked with in and placed at the end of the value; Meters are marked with m and placed at the end of the value.

1 m = 39.37 inches

Example 1: 10m

Example 2: 20in


TempStr = input()
if TempStr[-2] in['i','I']:
  C = eval(TempStr[0:-2])/39.37
  print("{:.3f}m".format(C))
elif TempStr[-1] in['m','M']:
  F = 39.37*eval(TempStr[0:-1])
  print("{:.3f}in".format(F))
else:
  print(" Wrong input format ")


Related articles: