0

I am using python 3.4.1. I keep getting this error,

 (NameError: name 'calcHullSpeed' is not defined)

What am I doing wrong?

import math

LWL = float(input("Enter the length of the boat: "))
maxHullSpeed = calcHullSpeed(LWL)
print("The hull speed is: " + str(round(maxHullSpeed,2)))

def calcHullSpeed(LWL):
    maxHS = 1.34*math.sqrt(LWL)
    return maxHS
BigO
  • 334
  • 1
  • 3
  • 16
user2981423
  • 45
  • 1
  • 7
  • 9

1 Answers1

2

Put your function first:

def calcHullSpeed(LWL):
    maxHS = 1.34*math.sqrt(LWL)
    return maxHS

LWL = float(input("Enter the length of the boat: "))
maxHullSpeed = calcHullSpeed(LWL)
print("The hull speed is: " + str(round(maxHullSpeed,2)))

Functions have to be defined before you call them.

Padraic Cunningham
  • 176,452
  • 29
  • 245
  • 321