张纸以毫米为单位

时间:2014-10-15 09:52:11

标签: python

我被要求编写一个程序,以毫米为单位显示letter尺寸(8.5 x 11英寸)纸张的尺寸。每英寸有25.4毫米。我需要在程序中使用常量和注释。这就是我想出的:

#This is a program that displays dimensions of a letter-size
#sheet of paper in millimeters.
# Conversion from inches to millimeters.
# w = 8.5 inches * 25.4mm/inch = 215.9 mm
# h = 11 inches *25.4mm/inch = 279.4 mm
# Define constants
WIDTH_IN_MILLIMETERS = 215.9
HEIGHT_IN_MILLIMETERS = 279.4

#Compute and print dimmensions of a letter-size sheet of paper in millimeters.
dimLetterSize = WIDTH_IN_MILLIMETERS * HEIGHT_IN_MILLIMETERS

print("The dimentions of a letter-size sheet of paper in millimeters: %6d" % dimLetterSize)

1 个答案:

答案 0 :(得分:-1)

以下是我对你的任务的回答。我希望你能得到满分。

# This is a program that displays dimensions of a letter-size
# sheet of paper in millimeters.

WIDTH = 8.5
HEIGHT = 11

MILLIMETERS_IN_INCHES = 25.4

print("The dimentions of a letter-size sheet of paper in millimeters is : {} x {}", WIDTH * MILLIMETERS_IN_INCHES, HEIGHT * MILLIMETERS_IN_INCHES)