By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,267 Members | 1,800 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,267 IT Pros & Developers. It's quick & easy.

JES Problem

P: 1
Expand|Select|Wrap|Line Numbers
  1. from random import * 
  2.  
  3. def main():
  4.   showInformation("Welcome to the Math Tutor!")
  5.   n= randrange(1,1000)
  6.   m= randrange(1,1000)
  7.   useranswer= requestInteger("Answer this addition problem\n " + str(n) + "\n" "+ " +str (m))
  8.   sum= (m+n)
  9.  
  10. if useranswer == sum: # error here
  11.   showInformation ("correct!")
  12. else:
  13.   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.
Sep 22 '11 #1
Share this Question
Share on Google+
1 Reply


bvdet
Expert Mod 2.5K+
P: 2,851
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.
Sep 25 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.