Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # SAMS 2018, Programming Sections A and B
- #########################################
- # Full name: Britney Beatey
- # Andrew ID: bbeatey
- #########################################
- # DUE DATE: Sunday July 22nd, 5pm.
- # SUBMIT THIS FILE TO AUTOLAB. LATE SUBMISSIONS WILL NOT BE ACCEPTED.
- # For the functions below, erase the "return whatever" line and write the
- # appropriate code instead.
- # IMPORTANT NOTE:
- # You are not allowed to import any modules other than string, use lists or recursion.
- import string
- # Takes two strings, a person's first and last names, and returns a single string
- # that contains their last and first name, with the first letter in each properly
- # capitalized, and with the last name separated from the first by a comma and a
- # single space. For example, joinNames("Natalie","smith") would return "Smith, Natalie"
- #
- def joinNames(first, last):
- string1 = first
- string1 = string1.capitalize()
- string2 = last
- string1 = string2.capitalize()
- string3 = string2 + ", " + string1
- return string3
- # DNA strands are made up of 4 molecules called nucleotides. They are Adenine,
- # Cytosine, Guanine, and Thymine (abbreviated A, C, G, T). A pairs up with T and
- # C pairs up with G. Two strands are considered complementary if each nucleotide
- # in one strand can pair up with the corresponding nucleotide in the other strand.
- # For example, AACG is complementary with TTGC. This function returns True if the
- # two string parameters are complementary DNA strands and False otherwise. You
- # cannot assume that the input strings will only contain A, C, G, T (and should return
- # False if either string has other characters)
- def areComplementary(strand1, strand2):
- return False
- # Given an integer parameter, returns True if it is palindromic (the same digit sequence
- # when read forward and backwards). Negative integers are not palindromic. You are not
- # allowed to convert the integer into a string and just use the string palindrome
- # function that we wrote in class!
- def isIntPalindrome(n):
- return False
- # Given a specific height, the function returns a string that represents an isosceles
- # ASCII triangle with height rows. There should be no spaces between the asterisks that
- # make up the triangle, nor should there be any "extra" spaces on any row. The result
- # of printing the strings returned from two sample function calls should give you an idea
- # of what is expected:
- #
- #print(asciiTriangle(3))
- # *
- # ***
- #*****
- #
- #print(asciiTriangle(5))
- # *
- # ***
- # *****
- # *******
- #*********
- def asciiTriangle(height):
- return "empty"
- # takes a non-empty string and returns a lowercase string that contains the most frequently
- # occurring letter(s) in s in alphabetical order (ignoring case in the original string)
- # you will likely need a nested loop for this...
- def mostFrequentLetter(s):
- return "empty"
- ######################################################################
- # ignore_rest: The autograder will ignore all code below here
- ######################################################################
- import math
- def testJoinNames():
- print("Testing joinNames()...", end="")
- assert(joinNames("Mark","Stehlik") == "Stehlik, Mark")
- assert(joinNames("donald","trump") == "Trump, Donald")
- assert(joinNames("x","Y") == "Y, X")
- print("Passed. (Add more tests to be more sure!)")
- def testAreComplementary():
- print("Testing areComplementary...", end="")
- assert(areComplementary("A","T") == True)
- assert(areComplementary("CTAGG","GATCC") == True)
- assert(areComplementary("CTA","AAT") == False)
- assert(areComplementary("CTA","GATT") == False)
- assert(areComplementary("CTACGC","GAT") == False)
- assert(areComplementary("GGcT","CCGA") == False)
- assert(areComplementary("GGCT","cCGA") == False)
- assert(areComplementary('ACGT', 'TGCA') == True)
- assert(areComplementary('ATT', 'TAT') == False)
- assert(areComplementary('ACGT', 'ACGT') == False)
- assert(areComplementary('CCC', 'GGG') == True)
- assert(areComplementary('C', 'g') == False)
- assert(areComplementary('c', 'g') == False)
- assert(areComplementary('', '') == False)
- print("Passed. (Add more tests to be more sure!)")
- def testIsIntPalindrome():
- print("Testing isIntPalindrome...", end="")
- assert(isIntPalindrome(123321) == True)
- assert(isIntPalindrome(-123321) == False)
- assert(isIntPalindrome(1239321) == True)
- assert(isIntPalindrome(123324) == False)
- assert(isIntPalindrome(123421) == False)
- print("Passed. (Add more tests to be more sure!)")
- def testAsciiTriangle():
- print("Testing asciiTriangle...", end="")
- assert(asciiTriangle(3) == " *\n ***\n*****\n")
- print("Passed. (Add more tests to be more sure!)")
- def testMostFrequentLetter():
- print("Testing mostFrequentLetter...",end="")
- assert(mostFrequentLetter("ZgVhyaBbv.....") == "bv")
- assert(mostFrequentLetter("c D B a") == "abcd")
- assert(mostFrequentLetter(". ") == "")
- print("Passed. (Add more tests to be more sure!)")
- def testAll():
- testJoinNames()
- testAreComplementary()
- testIsIntPalindrome()
- testAsciiTriangle()
- testMostFrequentLetter()
- testAll()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement