[Tutor] Begginer Python Problems - Urgent! Due by tomorrow morning.
alan.gauld at btinternet.com
Fri Sep 3 11:10:17 CEST 2010
"Colleen Glaeser" <songbird42371 at gmail.com> wrote
> Although it is all clearly legible, I still think something with my
> is not working.
Why, can you explain what you think should happen?
> If I run the program in the shell, I should be getting something
> that asks
> for a number, and I need to try positive and negative numbers and
> see what
> spits out.
Where do you think your code asks for a number?
> However, I'm getting the number 24, and a repetition of the words
> and "Greetings, earthlings."
That seems to be what your code prints so it would appear to be
> What am I doing wrong? Can anybody help? D: I need to turn my
> results in
> to class tomorrow morning!
> x = 12
> print (2*x)
Here is your 24
> def greetings():
> for i in range (3):
> print ('Hello ')
> print ('Greetings, earthling')
And this repeatedly prints Hello and Greetings Earthling
> def regreet():
> for j in range(4):
And this calls greetings() repeatedly, so even
more printing of the messages.
And this actually calls regreet() which triggers the whole thing off.
So your code appears to be doing exactly what you told it to do.
Where should the reading of numbers come in?
And what would you do with the numbers when you got them?
You might find the "Talking to the user" topic of my tutorial useful.
Author of the Learn to Program web site
More information about the Tutor