[Tutor] Begginer Python Problems - Urgent! Due by tomorrow morning.
steve at pearwood.info
Fri Sep 3 11:20:30 CEST 2010
On Fri, 3 Sep 2010 02:11:08 pm Colleen Glaeser wrote:
> Dear Python Tutors,
> I'm having trouble while typing a beginner program for python.
> Due to troublesome circumstances, I had to take pictures of the
> assignment sheet on my phone, and work from that.
> Although it is all clearly legible, I still think something with my
> program is not working.
> 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.
There's nothing in your program that actually asks the user for a
number. You need to use the function input(), like this:
answer = input("Hello puny human, give me a number. ")
If you type (say) 42 then press the Enter key, the variable answer will
be set to the string "42". You then need to change it to an integer:
number = int(answer)
or a float:
number = float(answer)
> However, I'm getting the number 24, and a repetition of the words
> "Hello" and "Greetings, earthlings."
Yes, that's because greetings() prints "Hello" three times, followed
by "Greetings earthling" once. Then regreet() calls greetings() four
times in a row, so it prints "Hello" twelve times in total
and "Greetings earthling" four times.
> This below is my program, and I've retyped it too many times to
> remember, while looking at the assignment sheet.
> What am I doing wrong? Can anybody help? D: I need to turn my
> results in to class tomorrow morning!
I hope the above clues will set you on the right track.
We won't do your homework for you, but if you come back with *specific*
questions, we can help.
More information about the Tutor