Did I do this correctly..Due in 11hrs..Can this program be written in other ways?

Thread Solved

Join Date: Feb 2006
Posts: 43
Reputation: butterflyTee is an unknown quantity at this point 
Solved Threads: 0
butterflyTee butterflyTee is offline Offline
Light Poster

Did I do this correctly..Due in 11hrs..Can this program be written in other ways?

 
0
  #1
Apr 13th, 2006
  1. # tpm.py
  2. # Take two inputs, age and years of citizenship, and returns eligibility for
  3. # senator and representative.
  4.  
  5. from graphics import *
  6.  
  7. def main():
  8. win = GraphWin('Eligibility' , 400,400)
  9. win.setCoords(0.0,0.0, 4.0, 4.0)
  10.  
  11. Text(Point(1, 3.0), 'Age').draw(win)
  12. Text(Point(1, 2.0), 'Years Citizen').draw(win)
  13. agebox = Entry(Point(2, 3.0), 10)
  14. agebox.draw(win)
  15. citizenshipbox = Entry(Point(2, 2.0), 10)
  16. citizenshipbox.draw(win)
  17. output = Text(Point(2.0, 1.0), 'Eligibility')
  18. output.draw(win)
  19.  
  20. win.getMouse()
  21. age = eval(agebox.getText())
  22. citizenship = eval(citizenshipbox.getText())
  23.  
  24.  
  25. if 30 > age >= 25:
  26. if citizenship >= 7:
  27. output.setText('Eligible for US representative')
  28. else:
  29. output.setText('Ineligible for US representative')
  30. elif age >= 30:
  31. if citizenship >= 9:
  32. output.setText('Eligible for US senator and US representative')
  33. elif 9 > citizenship >= 7:
  34. output.setText('Ineligible for US senator, eligible for US representative')
  35. else:
  36. output.setText('Ineligible for US senator or representative')
  37.  
  38. win.getMouse()
  39. win.close()
  40.  
  41. main()
:o

Edit: Added code tags, see http://www.daniweb.com/techtalkforum...ment114-3.html
Last edited by vegaseat; Apr 13th, 2006 at 10:16 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,025
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 932
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Did I do this correctly..Due in 11hrs..Can this program be written in other ways?

 
0
  #2
Apr 13th, 2006
I don't have the graphics module, but I tested your logic and found it faulty. Here is my test code:
[PHP]age = int(raw_input("years of age: "))
citizenship = int(raw_input("years citizen: "))

# age 25 to less than 30
if 25 <= age < 30:
if citizenship >= 7:
print 'Eligible for US representative'
else:
print 'Ineligible for US representative'
# age 30 and more
elif age >= 30:
if citizenship >= 9:
print 'Eligible for US senator and US representative'
elif 7 <= citizenship < 9:
print 'Ineligible for US senator, eligible for US representative'
# does not meet any of the conditions
else:
print 'Ineligible for US senator or representative'[/PHP]
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 43
Reputation: butterflyTee is an unknown quantity at this point 
Solved Threads: 0
butterflyTee butterflyTee is offline Offline
Light Poster

Re: Did I do this correctly..Due in 11hrs..Can this program be written in other ways?

 
0
  #3
Apr 13th, 2006
Thanks for your help..
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC