Congress Exercise in python language

Congress Exercise in python language
java programming and c, c++, Matlab, Python, HTML, CSS programming language, and new techniques news and any history.

Congress Exercise in python language
Congress Exercise in python language
























A person is eligible to be a US Senator who is at least 30 years old and has been a US citizen for at least 9 years. Write an initial version of a program congress.py to obtain age and length of citizenship from the user and print out if a person is eligible to be a Senator or not.
A person is eligible to be a US Representative who is at least 25 years old and has been a US citizen for at least 7 years. Elaborate your program congress.py so it obtains age and length of citizenship and prints out just the one of the following three statements that is accurate:
1.     You are eligible for both the House and Senate.
2.     You eligible only for the House.

3.     You are ineligible for Congress.

More String Methods

More String Methods












Here are a few more string methods useful in the next exercises
·         s.startswith( pre )returns True if string s starts with string pre: Both '-123'.startswith('-') and 'downstairs'.startswith('down') are True, but '1 - 2 - 3'.startswith('-')is False.
·         s.endswith( suffix returns True if string s ends with string suffix: Both 'whoever'.endswith('ever') and 'downstairs'.endswith('airs') are True, but '1 - 2 - 3'.endswith('-') is False.
·         s.replace( sub , replacement , count )returns a new string with up to the first count occurrences of string sub replaced by replacement. The replacement can be the empty string to delete sub. For example:
s = '-123'
t = s.replace('-', '', 1) # t equals '123'
t = t.replace('-', '', 1) # t is still equal to '123'
u = '.2.3.4.'
v = u.replace('.', '', 2) # v equals '23.4.'

Article Start Exercise

Article Start Exercise in python language












In-library alphabetizing, if the initial word is an article (“The”, “A”, “An”), then it is ignored when ordering entries. Write a program completing this function, and then testing it:
def startsWithArticle(title):
    '''Return True if the first word of title is "The", "A" or "An".'''

Be careful, if the title starts with “There”, it does not start with an article. What should you be testing for?

Is Number String Exercise
** In the later Safe Number Input Exercise, it will be important to know if a string can be converted to the desired type of number. Explore that here. Save example isNumberStringStub.py as isNumberString.py and complete it. It contains headings and documentation strings for the functions in both parts of this exercise.
A legal whole number string consists entirely of digits. Luckily strings have an isdigit method, which is true when a non-empty string consists entirely of digits, so '2397'.isdigit() returns True, and '23a'.isdigit() returns False, exactly corresponding to the situations when the string represents a whole number!

In both parts be sure to test carefully. Not only confirm that all appropriate strings return True. Also be sure to test that you return False for all sorts of bad strings.
a.  Recognizing an integer string is more involved since it can start with a minus sign (or not). Hence the isdigit method is not enough by itself. This part is the most straightforward if you have worked on the sections String Indices and String Slices. An alternate approach works if you use the count method from Object Orientation and some methods from this section. Complete the function isIntStr.
b.  Complete the function isDecimalStr, which introduces the possibility of a decimal point. The string methods mentioned in the previous part remain useful.

This is an improvement that is new in Python 3.0

If you divide an even number by 2, what is the remainder? Use this idea in your if condition.

4 tests to distinguish the 5 cases, as in the previous version


Once again, you are calculating and returning a Boolean result. You do not need an if-else statement.










Comments