Preliminary Python Game

Below is the code for a Python game I have almost finished, entitled “Heap Of Beans”; in which a user competes against the computer to draw the final “bean” in the pile of sixteen. This program is still under development, and will be complete shortly.

# Problem 1
#
# Program Explanation: This program is the "Easy" function for the "Heap of Beans" program, and makes the computer player predictable to the user by
# only allowing the computer to deduct one bean each turn.
#
# Test Case 1:
# Please enter the difficulty you would like to utilize.  Easy
# There are 16 beans in the pile.
# The amount of beans subtracted by the computer player is: 1.
# There are 15 beans remaining.
# Please enter the number of beans you would like to remove from the heap. 3
# The amount of beans subtracted by the computer player is: 1.
# There are 11 beans remaining.
# Please enter the number of beans you would like to remove from the heap. 2
# The amount of beans subtracted by the computer player is: 1.
# There are 8 beans remaining.
# Please enter the number of beans you would like to remove from the heap. 3
# The amount of beans subtracted by the computer player is: 1.
# There are 4 beans remaining.
# Please enter the number of beans you would like to remove from the heap. 2
# The amount of beans subtracted by the computer player is: 1.
# There are 1 beans remaining.
# Please enter the number of beans you would like to remove from the heap. 1
# You won!!
#
#
# Test Case 2:
# Please enter the difficulty you would like to utilize.  Easy
# There are 16 beans in the pile.
# The amount of beans subtracted by the computer player is: 1.
# There are 15 beans remaining.
# Please enter the number of beans you would like to remove from the heap. 2
# The amount of beans subtracted by the computer player is: 1.
# There are 12 beans remaining.
# Please enter the number of beans you would like to remove from the heap. 3
# The amount of beans subtracted by the computer player is: 1.
# There are 8 beans remaining.
# Please enter the number of beans you would like to remove from the heap. 3
# The amount of beans subtracted by the computer player is: 1.
# There are 4 beans remaining.
# Please enter the number of beans you would like to remove from the heap. 1
# The amount of beans subtracted by the computer player is: 1.
# There are 2 beans remaining.
# Please enter the number of beans you would like to remove from the heap. 1
# You lost!!
# The amount of beans subtracted by the computer player is: 1.
import random
def Easy(beans):
  print "There are 16 beans in the pile. "
  computerSubtract = 1
  while beans >= 0:
    beans -= computerSubtract
    if beans >0:
      print "The amount of beans subtracted by the computer player is: "+str(computerSubtract)+"."
    if beans >0:
      print "There are "+str(beans)+" beans remaining."
    if beans >0:
      playerSubtract = input("Please enter the number of beans you would like to remove from the heap. ")
      beans-=playerSubtract
      if beans == 0:
        print "You won!!"
    if beans ==1:
      print "You lost!!"
      print "The amount of beans subtracted by the computer player is: "+str(computerSubtract)+"."

  return beans
# Problem 2
#
# Program Explanation: This function expands upon Problem 1, allowing the computer player to choose any random (integer) number of beans, between 1 and 3.
#
#
# Test Case 1:
# Please enter the difficulty you would like to utilize.  Medium
# There are 16 beans in the pile.
# The amount of beans subtracted by the computer player is: 2.
# There are 14 beans remaining.
# Please enter the number of beans you would like to remove from the heap. 3
# The amount of beans subtracted by the computer player is: 3.
# There are 8 beans remaining.
# Please enter the number of beans you would like to remove from the heap. 2
# The amount of beans subtracted by the computer player is: 1.
# There are 5 beans remaining.
# Please enter the number of beans you would like to remove from the heap. 3
# The amount of beans subtracted by the computer player is: 1.
# There are 1 beans remaining.
# Please enter the number of beans you would like to remove from the heap. 1
# You won!!
#
#
# Test Case 2:
# Please enter the difficulty you would like to utilize.  Medium
# There are 16 beans in the pile.
# The amount of beans subtracted by the computer player is: 1.
# There are 15 beans remaining.
# Please enter the number of beans you would like to remove from the heap. 2
# The amount of beans subtracted by the computer player is: 2.
# There are 11 beans remaining.
# Please enter the number of beans you would like to remove from the heap. 3
# The amount of beans subtracted by the computer player is: 3.
# There are 5 beans remaining.
# Please enter the number of beans you would like to remove from the heap. 2
# The amount of beans subtracted by the computer player is: 3.
# You lost!
def Medium(beans):
  print "There are 16 beans in the pile. "
  while beans > 0:
    computerSubtract = random.randint(1,3)
    while computerSubtract > beans:
      computerSubtract = random.randint(1,3)
    beans-=computerSubtract
    if beans >0:
      print "The amount of beans subtracted by the computer player is: "+str(computerSubtract)+"."
    if beans ==0:
      print "The amount of beans subtracted by the computer player is: "+str(computerSubtract)+"."
      print "You lost!"
    if beans > 0:
      print "There are "+str(beans)+" beans remaining."
      playerSubtract = input("Please enter the number of beans you would like to remove from the heap. ")
      beans -= playerSubtract
      if beans == 0:
        print "You won!!"
    if beans <0:
      print "You lost!"

  return beans
# Problem 3
#
# Program Explanation: This function further expands upon the "Medium" difficulty, through the use of cascading "if-statements" to attempt to "guess" the user's input on the next turn,
# and a means of winning the game for the Computer player.
#
# Test Case 1:
# Please enter the difficulty you would like to utilize.  Hard
# There are 16 beans in the pile.
# Please enter the number of beans you would like to remove from the heap. 3
# The amount of beans subtracted by the computer player is: 3.
# There are 10 beans remaining.
# Please enter the number of beans you would like to remove from the heap. 2
# The amount of beans subtracted by the computer player is: 3.
# There are 5 beans remaining.
# Please enter the number of beans you would like to remove from the heap. 3
# The amount of beans subtracted by the computer player is: 2.
# You lost!
#
#
# Test Case 2:
# Please enter the difficulty you would like to utilize.  Hard
# There are 16 beans in the pile.
# Please enter the number of beans you would like to remove from the heap. 3
# The amount of beans subtracted by the computer player is: 3.
# There are 10 beans remaining.
# Please enter the number of beans you would like to remove from the heap. 2
# The amount of beans subtracted by the computer player is: 3.
# There are 5 beans remaining.
# Please enter the number of beans you would like to remove from the heap. 1
# The amount of beans subtracted by the computer player is: 3.
# There are 1 beans remaining.
# Please enter the number of beans you would like to remove from the heap. 1
# You won!!
#
#
# Test Case 3:
# Please enter the difficulty you would like to utilize.  Hard
# There are 16 beans in the pile.
# Please enter the number of beans you would like to remove from the heap. 3
# The amount of beans subtracted by the computer player is: 3.
# There are 10 beans remaining.
# Please enter the number of beans you would like to remove from the heap. 3
# The amount of beans subtracted by the computer player is: 2.
# There are 5 beans remaining.
# Please enter the number of beans you would like to remove from the heap. 3
# The amount of beans subtracted by the computer player is: 2.
# You lost!
def Hard(beans):
  print "There are 16 beans in the pile. "
  while beans > 0:
    playerSubtract = input("Please enter the number of beans you would like to remove from the heap. ")
    beans -= playerSubtract
    if beans == 0:
        print "You won!!"
    if beans <0:
      print "You lost!"
    if beans==3:
      computerSubtract=3
    if beans == 2:
      computerSubtract = 2
    if beans == 1:
      computerSubtract = 1
    if beans >=8 and beans <=14:
      computerSubtract = 3
    elif beans >=7 and beans >=2:
      computerSubtract = 2
    beans-=computerSubtract
    if beans >0:
      print "The amount of beans subtracted by the computer player is: "+str(computerSubtract)+"."
    if beans > 0:
      print "There are "+str(beans)+" beans remaining."
    if beans ==0:
      print "The amount of beans subtracted by the computer player is: "+str(computerSubtract)+"."
      print "You lost!"

  return beans


if __name__ == "__main__":
  beans = 16
  difficultySelect = raw_input("Please enter the difficulty you would like to utilize.  ")
  if str(difficultySelect)=="Easy":  
    beans = Easy(beans)
  elif str(difficultySelect)=="Medium":  
    beans = Medium(beans)
  elif str(difficultySelect)=="Hard":
    beans = Hard(beans)

Congress, The Federalist Papers, and a Fledgling Nation

The “necessary and proper” clause, within the eighth article of the United States Constitution is a critical and applicable means of maintaining governmental supremacy and organization. Our fear of a centralized and overwhelmingly powerful Federal Government lead to the creation of the Articles of Confederation, a document focused primarily on restraining a central government than transforming it into one that has the capacity to be both efficient and effective. Once apart from Great Britain, the growth of the power of our government is a “necessary evil”, and the possible domination of factions along with the various groups expecting clout within our new government require Congress to be able to carry out its enumerated powers without fail. Additionally, our nation has increased its level of international responsibility greatly.

            After the domineering nature of Great Britain’s monarchy, strict controls on a central government are paramount; however, they should not prevent that government from functioning. The Articles of Confederation provided for no Executive Branch, a Unicameral Legislature, and unanimous consent from each state before being ratified. These shortcomings were toxic to our nation, and came dangerously close to resulting in its destruction. While Anti-Federalists such as Patrick Henry and George Clinton have the opinion that the national government would become far too large to accurately represent the interests of its people, we (the Federalists) believe that a document as inadequate as the Articles of Confederation would limit the central government to such an extent that the progress of the United States would be stifled. Therefore, necessary to an effective central government is the “necessary and proper” clause within Article 8 of the Constitution, allowing for the adaptation of the Legislature as more requirements are placed upon it.

            Our Constitution created a large Republic, which contributes to the protection against factions within government. However, a large republic requires a level of government power that is able to grow and adapt based on present and future circumstances, requiring the “necessary and proper” clause as part of an active government to ensure its continuing functionality. In Federalist 10, James Madison argues that you can cure the “mischief of Factions” through controlling their effects; mainly preventing majority factions, securing against the danger of these factions, and ensuring a large Republic is created. The ideal remedy to the growing power requirements of our nation due to the creation of a large Republic is the “necessary and proper” clause, based on the fact that Congress will always, regardless of the size of the nation, have the need to use its enumerated powers. Furthermore, the situations requiring usage of Congress’ enumerated powers will change with time, as will the Constitution itself and factions seeking control of the government. Therefore, Congress will be unable to realize the full extent of its enumerated powers without the “necessary and proper” clause.

As a newly independent nation, there are international relations to be considered within our nation’s circumstances. Many congressional duties require the enumerated powers of the Legislature, and therefore the “necessary and proper” clause within the Constitution will ensure that Congress has the continuing power to make those laws that allow it to act in accordance with its enumerated powers. Of particular importance within the Constitutional enumerated powers for Congress include the capacity to “…collect Taxes, Duties, Imposts and Excises, to pay the Debts and provide for the common Defence and general welfare of the United States;…”[1] . Also, “To regulate Commerce with foreign Nations, and among the several States, and with the Indian Tribes;…”.[2] The continued ability of Congress to fulfill these powers is crucial to the growth and sustainment of our nation.

            A possible argument against the “necessary and proper” clause that could be made by Anti-Federalists is that this statute easily allows for the Federal Government to gain an excess of authority, and become oppressive. However, the “checks and balances” put in place by our Constitution prevents this. Furthermore, each law passed to allow Congress to use its “enumerated powers” must be passed in the same manner as every other law (requiring the consent of both houses), preventing the reckless expansion and increase in power of the Federal Government. Additionally, each law created under the “necessary and proper” clause must apply strictly to the activation and realization of Congress’ “enumerated powers”, and therefore could not expand governmental power beyond that of the Framers’ intent, due to the unchangeable nature of Congress’ “enumerated powers”.

            When the governing body of our nation was conceived by the Constitutional Conventions, it was known that the activeness and effectiveness of the new government was crucial to its survival. Due to the inadequacy of the Articles of Confederation, the growing governmental requirements for our nation, and the increasing level of international responsibility for the new nation, the “necessary and proper” clause was created.

 

 

 


[1] Benjamin Ginsberg and Erin Ackerman, A Guide to the United States Constitution(New York: W.W. Norton and Company, 2007), 13.

[2] Benjamin Ginsberg and Erin Ackerman, A Guide to the United States Constitution (New York: W.W. Norton and Company, 2007), 13.

Python

A few years ago, I set out to become fluent in Java, a programming language valued for its simplicity and applicability to a modern computing society. This usefulness is underscored by its presence within almost every computing platform – from smart phones to traffic light control systems. However, when starting classes within my concentration (major) of CS, I have been progressively gaining knowledge on a new language – Python. While more “modern” than Java, some of the conventions within Python (such as automatic determination of variable types, etc.) can be quite unnerving. Below, I have included a few lines within one of the first (and extremely simple) program I have written in Python. 

 

def StudentLoanCalculator():
interestRate = input("Please enter the interest rate of your loan (as a number). ")
initialBalance = input("Please enter the initial balance on the loan. $ ")
interestRate = interestRate*.01;
time = input("Please enter the amount of time (in years) you wish to wait to pay off the loan. ")
payoffBalance = (time*(initialBalance*interestRate))+initialBalance;
print "You must pay: $" +str(payoffBalance) + "0"
StudentLoanCalculator()