Problem with Boolean function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • softwareengineer2b
    New Member
    • Feb 2007
    • 1

    #1

    Problem with Boolean function

    As homework, I am to write a scrip that can determine if one integer is factor of another. I define the input x and y as follow;
    Code:
    def main():
    x = input ("What is the integer? ")
    y = input ("Enter another integer: ")
    
    def isfactor (x, y):
       if x % y == 0:
    
          print y, "is a factor of x."
      
      else:
         print y, "is not a factor x."
    
    main()
    For some reason the program only interprets up to the input parts and left the rest out. That is, when I run the program in shell, it prompts me to enter the integers and stop there. Can any body tell me why? your help will be greatly appreciated. Thank you very much.
    Last edited by bartonc; Feb 6 '07, 02:54 AM. Reason: added [code][/code] tags
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by softwareenginee r2b
    As homework, I am to write a scrip that can determine if one integer is factor of another. I define the input x and y as follow;
    Code:
    def main():
    x = input ("What is the integer? ")
    y = input ("Enter another integer: ")
    
    def isfactor (x, y):
       if x % y == 0:
    
          print y, "is a factor of x."
      
      else:
         print y, "is not a factor x."
    
    main()
    For some reason the program only interprets up to the input parts and left the rest out. That is, when I run the program in shell, it prompts me to enter the integers and stop there. Can any body tell me why? your help will be greatly appreciated. Thank you very much.
    You are in luck. We'll just shoot this over to the python forum and get you some help there. Welcome to TheScripts.com.

    Comment

    • bartonc
      Recognized Expert Expert
      • Sep 2006
      • 6478

      #3
      Originally posted by softwareenginee r2b
      As homework, I am to write a scrip that can determine if one integer is factor of another. I define the input x and y as follow
      For some reason the program only interprets up to the input parts and left the rest out. That is, when I run the program in shell, it prompts me to enter the integers and stop there. Can any body tell me why? your help will be greatly appreciated. Thank you very much.
      The second function call was never made. Here's one way to do it:
      Code:
      # I like to have subroutines on top and main() at the bottom
      def isfactor (x, y):
          if x % y == 0:
              print y, "is a factor of x."
          else:
              print y, "is not a factor x."
      
      def main():
          x = input ("What is the integer? ")
          y = input ("Enter another integer: ")
          isfactor(x, y)
      
      
      main()

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        By the way, welcome to the Python Forum on TheScripts.com. I'm glad you found this site and I really like you nic (wish I'd thought of that handle). Get all the python help you need here on TSDN.

        Comment

        Working...