Rosalee Dubberly said unto the world upon 2005-09-28 15:41:
> I am trying to learn Python to use in my lesson plans. I am using 
> Windows XP and the textbooks I am using are Beginning Python by WROX and 
> Learning Pyhton by O'Reilly.
> 
> I am definning a range of words 0 to 55, if the number is divisible by 
> 3,7,11 with no remainder print eggs, else print spam. This works.
> 
> def firstpart():
>   for n in range(0, 55):
>      if n % 3 == 0 or n % 7 == 0 or n % 11 == 0:
>          print 'eggs,',
>      else:
>          print 'spam,',
> # Now I am trying to modify the function to replace eggs with toast and 
> spam with jelly. I have spent days and nothing works. Can you send me in 
> the right direction??
> Rosa Dubberly
> [EMAIL PROTECTED]


Hi Rosa,

does this do the sort of thing you want?

 >>> def conditional_print(test_data, first_msg, second_msg):
        if test_data > 0:
                print first_msg
        else:
                print second_msg

                
 >>> conditional_print(5, "Positive!", "Non-positive!")
Positive!
 >>> conditional_print(-4, "Positive!", "Non-positive!")
Non-positive!
 >>> conditional_print(5, "Spam!", "Ham!")
Spam!
 >>> conditional_print("all strings are ", "greater than 0.", "less 
than o.")
greater than 0.
 >>>

Best,

Brian vdB

_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to