# 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()

:o

Edit: Added code tags, see http://www.daniweb.com/techtalkforums/announcement114-3.html

Recommended Answers

All 2 Replies

I don't have the graphics module, but I tested your logic and found it faulty. Here is my test code:

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'

Thanks for your help..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.