I am in a beginner programming class, and our instructor has chose Python as the language we are to work with. He has given us a very very simple assignment, which I will post, and the code that I have come up with, which I will also post. I feel like such a damn idiot because I cannot understand why this is not working. I keep getting a global definition error, and the teacher looks at us like we are the scum of the universe if we ask a question.
The assignment is:
Design a modular python program that asks the user to enter a distance in kilometers and then converts that distance to miles.
The program should loop for new input until told to stop by the person running the program.
hint: an input of zero (0) kilometers could be used to stop the program
The conversion formula is as follows: Miles = Kilometers * 0.6214
A minimum of three modules is required:
- input
- calculate
And the code I came up with is:
def main(ans):
while ans=='yes':
data()
calculate()
words()
def data():
print 'Enter Kilometers Please'
kilometers=input()
return
def calculate():
miles=kilometers*0.6214
print miles
def words():
print 'The number of miles is',
print 'Enter another number?'
ans='yes'
main(ans)
Can anyone tell me what I am doing wrong? Please remember we are just starting out, and I do not know many of the advanced coding techniques I have seen in these forums.