| | |
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:
Solved Threads: 0
Did I do this correctly..Due in 11hrs..Can this program be written in other ways?
0
#1 Apr 13th, 2006
Python Syntax (Toggle Plain Text)
# tpm.py # Take two inputs, age and years of citizenship, and returns eligibility for # senator and representative. from graphics import * def main(): win = GraphWin('Eligibility' , 400,400) win.setCoords(0.0,0.0, 4.0, 4.0) Text(Point(1, 3.0), 'Age').draw(win) Text(Point(1, 2.0), 'Years Citizen').draw(win) agebox = Entry(Point(2, 3.0), 10) agebox.draw(win) citizenshipbox = Entry(Point(2, 2.0), 10) citizenshipbox.draw(win) output = Text(Point(2.0, 1.0), 'Eligibility') output.draw(win) win.getMouse() age = eval(agebox.getText()) citizenship = eval(citizenshipbox.getText()) if 30 > age >= 25: if citizenship >= 7: output.setText('Eligible for US representative') else: output.setText('Ineligible for US representative') elif age >= 30: if citizenship >= 9: output.setText('Eligible for US senator and US representative') elif 9 > citizenship >= 7: output.setText('Ineligible for US senator, eligible for US representative') else: output.setText('Ineligible for US senator or representative') win.getMouse() win.close() main()
Edit: Added code tags, see http://www.daniweb.com/techtalkforum...ment114-3.html
Last edited by vegaseat; Apr 13th, 2006 at 10:16 am.
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]
[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!
•
•
Join Date: Feb 2006
Posts: 43
Reputation:
Solved Threads: 0
Re: Did I do this correctly..Due in 11hrs..Can this program be written in other ways?
0
#3 Apr 13th, 2006
![]() |
Similar Threads
- What's the HARDEST program you've written? (Computer Science)
- I Wrote Program In 2 Different Ways, And Still Not Running Correctly..past Due (Python)
- Vending Machine (C++)
Other Threads in the Python Forum
- Previous Thread: Question on HW problem
- Next Thread: Calculate Easter Sunday (Python)
| Thread Tools | Search this Thread |
alarm assignment avogadro beginner bluetooth character cmd code customdialog cx-freeze data decimals dictionary directory dynamic error examples exe file float format function generator getvalue gnu graphics gui halp homework http ideas import input ip itunes java leftmouse line linux list lists logging loop maintain maze millimeter module mouse number numbers output parsing path port prime programming projects push py2exe pygame pyglet pyqt python queue random recursion schedule screensaverloopinactive script scrolledtext slicenotation sqlite ssh stdout string strings sudokusolver table terminal text thread threading time tlapse tuple tutorial ubuntu unicode urllib urllib2 variable variables ventrilo verify vigenere web webservice wikipedia wxpython xlib






