Академический Документы
Профессиональный Документы
Культура Документы
Chapter 12 Problem 3
# Program that has 10 account ID's in which they can check balance, withdraw,
# deposit, and go back to main menu.
class Account:
# Initiate the class account
def __init__(self, id = 0, balance = 100, annualInterestRate = 0):
self.__id = id
self.__balance = balance
self.__annualInterestRate = annualInterestRate
# Get the ID
def getId(self):
return self.__id
# Get the current balance of the account
def getBalance(self):
return self.__balance
# Get the annual interest rate
def getAnnualInterestRate(self):
return self.__annualInterestRate
# Set the id for the account
def setId(self, id):
self.__id = id
# Set the balance of the account
def setBalance(self, balance):
self.__balance = balance
# Set the annual interest rate
def setAnnualInterestRate(self, rate):
self.__annualInterestRate = rate
# Get the monthly interest rate
def getMonthlyInterestRate(self):
return self.__annualInterestRate/ 12
Chapter 13 Problem 8
# Program that encodes a file by adding 5 to every byte in the file. Encrypted version of
# the input file is saved to the output file
def main():
# Get the input file
f1 = raw_input("Enter a source filename: ").strip()
# Get the output file
f2 = raw_input("Enter a target filename: ").strip()
# Open files for input
infile = open(f1, "r")
s = infile.read() # Read all from the file
newS = ""
# Encode file by adding 5 to every byte
for i in range(len(s)):
newS += chr(ord(s[i]) + 5)
infile.close() # Close the input file
outfile = open(f2, "w")
file = outfile
print newS, file # Write to the file
print "Encryption Completed"
outfile.close() # Close the output file
main()
Chapter 13 Problem 9
# Program that decodes a file by subtracting 5 to every byte in the file. Decrypted version of the
input file is saved to the output file
def main():
# Get the input file
f1 = raw_input("Enter a source filename: ").strip()
# Get the output file
f2 = raw_input("Enter a target filename: ").strip()
# Open files for input
infile = open(f1, "r")
s = infile.read() # Read all from the file
newS = ""
Chapter 14 Problem 2
# Program that counts and prints the number/s that appear the most.
def main():
s = raw_input("Enter the numbers: ").strip()