JES Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • raoulduke666
    New Member
    • Sep 2011
    • 1

    JES Problem

    Code:
    from random import * 
    
    def main():
      showInformation("Welcome to the Math Tutor!")
      n= randrange(1,1000)
      m= randrange(1,1000)
      useranswer= requestInteger("Answer this addition problem\n " + str(n) + "\n" "+ " +str (m))
      sum= (m+n)
    
    if useranswer == sum: # error here
      showInformation ("correct!")
    else:
      showInformation (str(useranswer) + " is incorrect,try again")
    I'm creating a little addition calculator. What you see noted is what my syntax error is and I can't figure out why its not pulling the variable "username". I think it may have to deal with the "if" condition, but I'm not sure My goal is for the user to answer an addition problem. They will have an answer if its correct or incorrect.
    Last edited by bvdet; Sep 25 '11, 04:12 PM. Reason: add code tags
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    The if/else block is not indented, therefore executes outside of the function main(). Variable username is local to function main() and will not be available.

    Comment

    Working...