i've started a study in programming in the Netherlands. but we don't get realy programming lessons.
so i started programming my self. a friend of my advided me to start with a east langage.
thats why i use python. but now i have a little problem.
a variable is not defined, i am a beginner, so i don't know what to do.
tips are welcome :D
here is my script:
import random
import time
def displayIntro():
print('Welcome to Williams BMI calculator.')
time.sleep(1)
print('This programm wil calculate your BMI for you.')
time.sleep(1)
print('BMI means Body Mass Index, it shows you of your are on a healthy weight')
print()
def enterInformation():
print('pleace enter your name')
myName = input()
print('Hello ' + myName + ' , Lets get started.')
print()
print('First typ in your weight in kg pleace.')
weight = int()
weight = input()
print('Okay, now typ in your length in cm pleace.')
length = int()
length = input()
calculateBMI()
def calculateBMI():
BMI = weight / (length*length)
if BMI < 20:
print('Your BMI is too low, you should gain some weight.')
if BMI > 25:
print('Your BMI is too high, you should loose some weight.')
else:
print('Your BMI is perfect, keep this weight and you will live a happy life.')
displayIntro()
calculateAgain = 'yes'
while calculateAgain == 'yes' or calculateAgain == 'y':
enterInformation()
print('Do you want to calculate your BMI again? (yes or no)')
calculateAgain = input()
the output/ errors are:
>>>
Welcome to Williams BMI calculator.
This programm wil calculate your BMI for you.
BMI means Body Mass Index, it shows you of your are on a healthy weight
pleace enter your name
William
Hello William , Lets get started.
First typ in your weight in kg pleace.
80
Okay, now typ in your length in cm pleace.
185
Traceback (most recent call last):
File "D:\python apps\BMI calculator.py.py", line 42, in <module>
enterInformation()
File "D:\python apps\BMI calculator.py.py", line 25, in enterInformation
calculateBMI()
File "D:\python apps\BMI calculator.py.py", line 28, in calculateBMI
BMI = weight / (length*length)
NameError: global name 'weight' is not defined
>>>
Edited by Dorgon, 11 November 2010 - 05:09 AM.


Sign In
Create Account


Back to top









