944,110 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 1431
  • Python RSS
Apr 13th, 2006
0

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

Expand Post »
Python Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
butterflyTee is offline Offline
43 posts
since Feb 2006
Apr 13th, 2006
0

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

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]
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Apr 13th, 2006
0

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

Thanks for your help..
Reputation Points: 10
Solved Threads: 0
Light Poster
butterflyTee is offline Offline
43 posts
since Feb 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Question on HW problem
Next Thread in Python Forum Timeline: Calculate Easter Sunday (Python)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC