2016-06-28 4 views
-1

저는 처음으로 프로그래밍 수업을 듣고 있으며, 두 번째 실험실에서는 이미 내 엉덩이를 걷어차 고 있습니다.수학 계산을 수행하는 프로그램을 작성하십시오.

교수는 사용자로부터 십진법 (입력)으로 피트 단위로 측정 한 후 피트 및 인치 단위로 별도로 출력 (출력) 할 수있는 프로그램을 작성하길 원합니다.

시작하는 방법에 혼란 스럽습니다.

print ("This program will convert your measurement (in feet) into feet and inches.") 
print() 

# input section 
userFeet = int(input("Enter feet: ")) 

# conversion 
feet =() 
inches = feet * 12 

#output section 
print ("You are",userFeet, "tall.") 
print (userFeet "feet is equivalent to" feet "feet" inches "inches") 

을하고 난 당장은 모른다 : 우리의 결과처럼 보이도록 생각되는이 내가 지금까지 무엇을 가지고

"10.25 피트 10 개 피트 3인치에 해당합니다." 저는 인치를 인치로, 그리고 그 반대로도 변환하는 것을 이해합니다. 하지만 나는 발에서 피트와 인치로 따로 변환하는 것을 이해하지 못합니다.

가능한 경우 도움주세요! 감사!

+0

[this] (https://docs.python.org/2/library/tokenize.html) –

답변

1

나는 내가 변경 한 것에 대한 의견을 바탕으로 귀하의 코드를 수정하려고 노력할 것입니다.

import math # This is a module. This allows you to access more commands. You can see the full list of "math" commands with this link: https://docs.python.org/2/library/math.html 

print ("This program will convert your measurement (in feet) into feet and inches.") 
print() 

# input section 
userFeet = float(input("Enter feet: ")) # You used integer, which would not support decimal numbers. Float values can, and it is noted with float() 

# conversion 
feet = math.floor(userFeet) # This uses the floor command, which is fully explained in the link. 
inches = (userFeet - feet) * 12 

#output section 
print ("You are", str(userFeet), "tall.") 
print (userFeet, "feet is equivalent to", feet, "feet", inches, "inches") # You forgot to add the commas in the print command. 
1

인쇄 할 다리는 userFeet의 정수 부분에 불과합니다. 인치는 변환 후 십진수입니다. 200 분과 마찬가지로 3 시간 20 분입니다. 그래서 :

from math import floor 
print ("This program will convert your measurement (in feet) into feet and inches.") 
print() 

# input section 
userFeet = float(input("Enter feet: ")) 

# conversion 
feet = floor(userFeet) # this function simply returns the integer part of whatever is passed to it 
inches = (userFeet - feet) * 12 

#output section 
print("You are {} tall.".format(userFeet)) 
print("{0} feet is equivalent to {1} feet {2:.3f} inches".format(userFeet, feet, inches)) 
0

몇 가지 힌트 : (이것은 소수를 포함하기 때문에)

userFeet는 정수가 될 수 없습니다.

발 수는 float/double 유형의 정수로 채워질 수 있습니다.

인치의 수는 userFeet과 feet (userFeet - feet)의 차이에 12를 곱하여 가장 가까운 정수로 반올림하여 계산할 수 있습니다.

0
10.25 feet => 10feet + 0.25 feet => 10feet and 0.25*12inch => 10feet 3inch 

그래서 소수 부분을 다음 그냥 같이 인치의 발 수와 수를 표시 인치를 얻기 위해 (12)에 의해 곱합니다.

관련 문제