정의 된 방정식이 올바르게 변환되지 않음

새긴 ​​금

입력 한 영국식 측정 값을 미터법으로 변환하려고하는데 변환이 올바르지 않고 그 이유를 잘 모르겠습니다. 예를 들어, 50 파운드의 총 중량 영국식 단위 입력을 합하면 출력은 17.72kg이됩니다. 조언, 비평가 또는 코드 변경을 환영합니다. 이것은 내 코드입니다.

# Convert the total weight from Imperial, to Metric units
def convertWeight(totalWeight):
  return (totalWeight * 0.45359237)

# Calculate the cost of transport, by multiplying certain weight conditions by their respective cost per kilograms
def getRate(totalWeight):
  if totalWeight <= 2:
      rate = totalWeight * 1.10
  elif totalWeight > 2 and totalWeight <= 6:
      rate = totalWeight * 2.20
  elif totalWeight > 6 and totalWeight <= 10:
      rate = totalWeight * 3.70
  elif totalWeight > 10:
      rate = totalWeight * 4.20
  return rate

# Get the number of boxes
numBoxes = int(input('Please enter the number of boxes: '))
# Get the unit of measurement
unit = input('Please enter the unit of measurement, Imperial or Metric (as I or M): ')
# If the inputted unit of measurement does not equal one of these conditions, ask again for the unit of measurement, until one of these characters are inputted.
while unit not in ['I','M','i','m']:
   unit = input('Please enter the unit of measurement again, Imperial or Metric (as I or M): ')

totalWeight = 0
# For each box, get their respective weight
for x in range(numBoxes):
   weight = float(input('Please enter the weight of the boxes: '))
# Sum up the total weight by adding the inputted weights
   totalWeight = totalWeight + weight
# Does not work, check Parlas answers ; If the inputted unit is Imperial, convert it to Metric
   if unit in ['I', 'i']:
       totalWeight = convertWeight(totalWeight)
   else:
      totalWeight = totalWeight

# Calculate the transport cost, by calling the rate function
transportCost = getRate(totalWeight)
# Output the number of boxes, the total weight, and the transport cost to the user
print('The number of boxes is {0}, the total weight is {1:.2f} kilograms, and the transport cost is ${2:,.2f}.' .format(numBoxes, totalWeight, transportCost))
휴 보스 웰

문제는 임페리얼 체중 변환이

   if unit in ['I', 'i']:
       totalWeight = convertWeight(totalWeight)

get-weights 루프 안에 있습니다.

for x in range(numBoxes):
    weight = float(input('Please enter the weight of the boxes: '))
    # Sum up the total weight by adding the inputted weights
    totalWeight = totalWeight + weight

따라서 (예를 들어) 각각 무게가 25 파운드 인 2 개의 상자가있는 경우 미터법 무게는이어야 (25 + 25) * 0.4536하지만 대신 계산하는 것 ((25 * 0.4536) + 25) * 0.4536입니다.

모든 가중치를 얻은 후에 만 변환이 발생하는지 확인하십시오 .

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

CSV 파일의 수정 된 값이 올바르게 가져 오지 않음

분류에서Dev

Python의 정규식이 올바르게 일치하지 않음

분류에서Dev

정규식이 올바르게 검증되지 않음

분류에서Dev

중첩 된 XML 노드가 올바르게 정렬되지 않음

분류에서Dev

비활성화 된 버튼의 스타일이 올바르게 지정되지 않음

분류에서Dev

Pandas-sort_values가 변환 된 부동 비율을 올바르게 정렬하지 않음

분류에서Dev

파이썬이 방정식을 올바르게 계산하지 않음

분류에서Dev

메서드가 올바르게 재정의되지 않음

분류에서Dev

AngularJS : 컨트롤러 내부에 정의 된 변수 값이 올바르게 표시되지 않습니다.

분류에서Dev

목록 항목의 중첩 된 UI가 가로로 올바르게 정렬되지 않음

분류에서Dev

중첩 된 스크롤 창 내의 고정 HTML 요소가 올바르게 렌더링되지 않음

분류에서Dev

양식 필드가 올바르게 정렬되지 않음

분류에서Dev

계산 정렬이 올바르게 정렬되지 않음

분류에서Dev

선택 정렬이 올바르게 정렬되지 않음

분류에서Dev

긁힌 NBA 일정이 올바르게 정렬되지 않음

분류에서Dev

IF 문에 정의되지 않은 변수 (하지만 올바르게 선언 된 것처럼 보임)

분류에서Dev

테이블 키가 올바르게 정렬되지 않음

분류에서Dev

div 행이 올바르게 정렬되지 않음

분류에서Dev

열이 올바르게 정렬되지 않음

분류에서Dev

탄력적 검색이 올바르게 정렬되지 않음

분류에서Dev

어레이 크기가 올바르게 설정되지 않음

분류에서Dev

슬라이드 쇼가 올바르게 고정되지 않음

분류에서Dev

riot v2.6.7에서 정렬 된 목록이 올바르게 표시되지 않음

분류에서Dev

DateTime ToString이 ddMMy 지정자로 올바르게 형식화되지 않음

분류에서Dev

소스 나뭇 가지의 색상이 올바르게 지정되지 않음

분류에서Dev

Ansible이 환경 변수를 올바르게 설정하지 않음

분류에서Dev

--convert-links가 지정된 경우 wget이 URL을 올바르게 변환하지 않습니다.

분류에서Dev

Javascript 변수가 처음으로 올바르게 설정되지 않음

분류에서Dev

Android 툴바의 크기가 올바르게 조정되지 않음

Related 관련 기사

  1. 1

    CSV 파일의 수정 된 값이 올바르게 가져 오지 않음

  2. 2

    Python의 정규식이 올바르게 일치하지 않음

  3. 3

    정규식이 올바르게 검증되지 않음

  4. 4

    중첩 된 XML 노드가 올바르게 정렬되지 않음

  5. 5

    비활성화 된 버튼의 스타일이 올바르게 지정되지 않음

  6. 6

    Pandas-sort_values가 변환 된 부동 비율을 올바르게 정렬하지 않음

  7. 7

    파이썬이 방정식을 올바르게 계산하지 않음

  8. 8

    메서드가 올바르게 재정의되지 않음

  9. 9

    AngularJS : 컨트롤러 내부에 정의 된 변수 값이 올바르게 표시되지 않습니다.

  10. 10

    목록 항목의 중첩 된 UI가 가로로 올바르게 정렬되지 않음

  11. 11

    중첩 된 스크롤 창 내의 고정 HTML 요소가 올바르게 렌더링되지 않음

  12. 12

    양식 필드가 올바르게 정렬되지 않음

  13. 13

    계산 정렬이 올바르게 정렬되지 않음

  14. 14

    선택 정렬이 올바르게 정렬되지 않음

  15. 15

    긁힌 NBA 일정이 올바르게 정렬되지 않음

  16. 16

    IF 문에 정의되지 않은 변수 (하지만 올바르게 선언 된 것처럼 보임)

  17. 17

    테이블 키가 올바르게 정렬되지 않음

  18. 18

    div 행이 올바르게 정렬되지 않음

  19. 19

    열이 올바르게 정렬되지 않음

  20. 20

    탄력적 검색이 올바르게 정렬되지 않음

  21. 21

    어레이 크기가 올바르게 설정되지 않음

  22. 22

    슬라이드 쇼가 올바르게 고정되지 않음

  23. 23

    riot v2.6.7에서 정렬 된 목록이 올바르게 표시되지 않음

  24. 24

    DateTime ToString이 ddMMy 지정자로 올바르게 형식화되지 않음

  25. 25

    소스 나뭇 가지의 색상이 올바르게 지정되지 않음

  26. 26

    Ansible이 환경 변수를 올바르게 설정하지 않음

  27. 27

    --convert-links가 지정된 경우 wget이 URL을 올바르게 변환하지 않습니다.

  28. 28

    Javascript 변수가 처음으로 올바르게 설정되지 않음

  29. 29

    Android 툴바의 크기가 올바르게 조정되지 않음

뜨겁다태그

보관