Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Students/A.Kramer/session03/ROT13.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'''
Created on Oct 1, 2014

@author: db345c
'''

def rot13(s):
alpha1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz .!<>;:'"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting approach.

Check out the stri.translate() method -- it does kind of the same thing, but much faster.

or you could use the math -- ord(letter) will give you the numerical value, which you can add 13 to, then use chr() to make it a letter.

but this is fine, too -- more than one way to write a function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not even think of ord() at the time of writing. I will try one
tomorrow.
On Oct 16, 2014 9:20 PM, "Christopher H.Barker, PhD" <
notifications@github.com> wrote:

In Students/A.Kramer/session03/ROT13.py:

@@ -0,0 +1,30 @@
+'''
+Created on Oct 1, 2014
+
+@author: db345c
+'''
+
+def rot13(s):

  • alpha1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz .!<>;:'"

interesting approach.

Check out the stri.translate() method -- it does kind of the same thing,
but much faster.

or you could use the math -- ord(letter) will give you the numerical
value, which you can add 13 to, then use chr() to make it a letter.

but this is fine, too -- more than one way to write a function.


Reply to this email directly or view it on GitHub
https://github.com/UWPCE-PythonCert/IntroToPython/pull/28/files#r19001135
.

alpha2 = "NOPQRSTUVWXYZabcdefgjijklmnopqrstuvwxyzABCDEFGHIJKLM .!<>;:'"

# string to return
ret = ""

for i in range(0, len(s)):
try:
if s[i].islower():
ret += alpha2[alpha1.index(s[i])].lower()
else:
ret += alpha2[alpha1.index(s[i])].upper()
except ValueError:
pass
else:
pass
return ret

# run the program with the assigned parameter
if __name__ == '__main__':
print rot13("Zntargvp sebz bhgfvqr arne pbeare")


52 changes: 52 additions & 0 deletions Students/A.Kramer/session03/list_lab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

def list_lab():

# Part 1
print "Part 1\n"
lst = ["Apples", "Pears", "Oranges", "Peaches"]
print lst
fruit = raw_input("Enter another fruit: ")
lst.append(fruit)
print lst
num = raw_input("Enter the nubmer: ")
print num, lst[int(num) -1]
print lst
lst.insert(0, "Grape")
print lst
for i in lst:
if i[0] == 'P':
print i,

# Part 2
print "\n\nPart 2\n"
print lst
lst.remove("Grape")
print lst
frt = raw_input("Enter the fruit to delete: ")
print lst.remove(frt)
print lst

# Part 3
print "\nPart 3\n"
for x in lst:
prmpt = "Do you like " + x + "? : "
a = raw_input(prmpt)
if a == "yes":
print x.lower()
elif a == "no":
lst.remove(x)

print lst

# Part 4
print "\nPart 4\n"
print "Original List", lst
lst2 = lst[::]
for idx, val in enumerate(lst2):
lst2[idx] = val[::-1]

print "Modified list", lst2


if __name__ == "__main__":
list_lab()
73 changes: 73 additions & 0 deletions Students/A.Kramer/session03/mailroom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@

def execute():
"""Run the main program """
donors = [["Jon Doe", 50, 2], ["Jane Doe", 35, 7], ["Anonymous", 30, 10]]
prompt = "Please, select the following options\n1 - Send a Thank you Letter\n2 - Create Report\n3 - Quit\n"
while True:
print prompt
answer = raw_input("What is your choice: ")
if answer == '2':
print_report(donors)
elif answer == '1':
generate_letters(donors)
elif answer == '3':
print "Have a good day"
break
else:
print "Unrecognized option"
print ""

def print_report(d):
"""Print users' report"""
for donor in d:
avg_amnt = 0
if donor[2] == 0:
avg_amnt = 0
else:
avg_amnt = donor[1]/donor[2]
print "Name: %s\tTotal Donated: $%2.2f\tNumber of Donations: %i\tAverage Donation: $%2.2f" % (donor[0], donor[1], donor[2], avg_amnt)
print ""

def generate_letters(d):
"""Generate Thank you letter"""
name = select_donor(d)
donation = get_donation(name)
email_text = "Dear " + name + ",\n\nThank you very much for your generous donation of $" + str(donation) + ".\nThis donation will go a long way."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try tho give string formatting a try for this -- much better if it gets more complicated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will try tomorrow.
On Oct 16, 2014 9:22 PM, "Christopher H.Barker, PhD" <
notifications@github.com> wrote:

In Students/A.Kramer/session03/mailroom.py:

+def print_report(d):

  • """Print users' report"""
  • for donor in d:
  •    avg_amnt = 0
    
  •    if donor[2] == 0:
    
  •        avg_amnt = 0
    
  •    else:
    
  •        avg_amnt = donor[1]/donor[2]
    
  •    print "Name: %s\tTotal Donated: $%2.2f\tNumber of Donations: %i\tAverage Donation: $%2.2f" % (donor[0], donor[1], donor[2], avg_amnt)
    
  • print ""

+def generate_letters(d):

  • """Generate Thank you letter"""
  • name = select_donor(d)
  • donation = get_donation(name)
  • email_text = "Dear " + name + ",\n\nThank you very much for your generous donation of $" + str(donation) + ".\nThis donation will go a long way."

try tho give string formatting a try for this -- much better if it gets
more complicated.


Reply to this email directly or view it on GitHub
https://github.com/UWPCE-PythonCert/IntroToPython/pull/28/files#r19001189
.

email_text = email_text + "\n\nThank you again,\n\nSupport Staff"
print "\n======================================================================="
print email_text
print "=======================================================================\n"
for k in d:
if k[0] == name:
k[1] = k[1] + float(donation)
k[2] = k[2] + 1

def get_donation(n):
"""Obtain donation ammount"""
while True:
amount = raw_input("\nProvide donation amount: ")
try:
if float(amount):
return float(amount)
except ValueError:
print "Invalid Number provided for donation"

def select_donor(d):
"""Obtain Donor name to use"""
while True:
n = raw_input("\nType the name of the donor or type the work 'list': ")
if n == "list":
print n == "list"
for x in d:
print x[0]
else:
for g in d:
if g[0] == n:
return n
d.append([n, 0, 0])
return n

if __name__ == "__main__":
"""Execute the main program"""
execute()