Advertisement
britneybeatey

hw3

Jul 17th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.21 KB | None | 0 0
  1. # SAMS 2018, Programming Sections A and B
  2. #########################################
  3. # Full name: Britney Beatey
  4. # Andrew ID: bbeatey
  5. #########################################
  6.  
  7. # DUE DATE: Sunday July 22nd, 5pm.
  8. # SUBMIT THIS FILE TO AUTOLAB. LATE SUBMISSIONS WILL NOT BE ACCEPTED.
  9.  
  10. # For the functions below, erase the "return whatever" line and write the
  11. # appropriate code instead.
  12.  
  13. # IMPORTANT NOTE:
  14. # You are not allowed to import any modules other than string, use lists or recursion.
  15. import string
  16.  
  17. # Takes two strings, a person's first and last names, and returns a single string
  18. # that contains their last and first name, with the first letter in each properly
  19. # capitalized, and with the last name separated from the first by a comma and a
  20. # single space. For example, joinNames("Natalie","smith") would return "Smith, Natalie"
  21. #
  22. def joinNames(first, last):
  23. string1 = first
  24. string1 = string1.capitalize()
  25. string2 = last
  26. string1 = string2.capitalize()
  27. string3 = string2 + ", " + string1
  28. return string3
  29.  
  30. # DNA strands are made up of 4 molecules called nucleotides. They are Adenine,
  31. # Cytosine, Guanine, and Thymine (abbreviated A, C, G, T). A pairs up with T and
  32. # C pairs up with G. Two strands are considered complementary if each nucleotide
  33. # in one strand can pair up with the corresponding nucleotide in the other strand.
  34. # For example, AACG is complementary with TTGC. This function returns True if the
  35. # two string parameters are complementary DNA strands and False otherwise. You
  36. # cannot assume that the input strings will only contain A, C, G, T (and should return
  37. # False if either string has other characters)
  38. def areComplementary(strand1, strand2):
  39. return False
  40.  
  41.  
  42. # Given an integer parameter, returns True if it is palindromic (the same digit sequence
  43. # when read forward and backwards). Negative integers are not palindromic. You are not
  44. # allowed to convert the integer into a string and just use the string palindrome
  45. # function that we wrote in class!
  46. def isIntPalindrome(n):
  47. return False
  48.  
  49.  
  50. # Given a specific height, the function returns a string that represents an isosceles
  51. # ASCII triangle with height rows. There should be no spaces between the asterisks that
  52. # make up the triangle, nor should there be any "extra" spaces on any row. The result
  53. # of printing the strings returned from two sample function calls should give you an idea
  54. # of what is expected:
  55. #
  56. #print(asciiTriangle(3))
  57. # *
  58. # ***
  59. #*****
  60. #
  61. #print(asciiTriangle(5))
  62. # *
  63. # ***
  64. # *****
  65. # *******
  66. #*********
  67. def asciiTriangle(height):
  68. return "empty"
  69.  
  70.  
  71. # takes a non-empty string and returns a lowercase string that contains the most frequently
  72. # occurring letter(s) in s in alphabetical order (ignoring case in the original string)
  73. # you will likely need a nested loop for this...
  74. def mostFrequentLetter(s):
  75. return "empty"
  76.  
  77.  
  78.  
  79. ######################################################################
  80. # ignore_rest: The autograder will ignore all code below here
  81. ######################################################################
  82.  
  83.  
  84. import math
  85.  
  86. def testJoinNames():
  87. print("Testing joinNames()...", end="")
  88. assert(joinNames("Mark","Stehlik") == "Stehlik, Mark")
  89. assert(joinNames("donald","trump") == "Trump, Donald")
  90. assert(joinNames("x","Y") == "Y, X")
  91. print("Passed. (Add more tests to be more sure!)")
  92.  
  93. def testAreComplementary():
  94. print("Testing areComplementary...", end="")
  95. assert(areComplementary("A","T") == True)
  96. assert(areComplementary("CTAGG","GATCC") == True)
  97. assert(areComplementary("CTA","AAT") == False)
  98. assert(areComplementary("CTA","GATT") == False)
  99. assert(areComplementary("CTACGC","GAT") == False)
  100. assert(areComplementary("GGcT","CCGA") == False)
  101. assert(areComplementary("GGCT","cCGA") == False)
  102. assert(areComplementary('ACGT', 'TGCA') == True)
  103. assert(areComplementary('ATT', 'TAT') == False)
  104. assert(areComplementary('ACGT', 'ACGT') == False)
  105. assert(areComplementary('CCC', 'GGG') == True)
  106. assert(areComplementary('C', 'g') == False)
  107. assert(areComplementary('c', 'g') == False)
  108. assert(areComplementary('', '') == False)
  109. print("Passed. (Add more tests to be more sure!)")
  110.  
  111. def testIsIntPalindrome():
  112. print("Testing isIntPalindrome...", end="")
  113. assert(isIntPalindrome(123321) == True)
  114. assert(isIntPalindrome(-123321) == False)
  115. assert(isIntPalindrome(1239321) == True)
  116. assert(isIntPalindrome(123324) == False)
  117. assert(isIntPalindrome(123421) == False)
  118. print("Passed. (Add more tests to be more sure!)")
  119.  
  120. def testAsciiTriangle():
  121. print("Testing asciiTriangle...", end="")
  122. assert(asciiTriangle(3) == " *\n ***\n*****\n")
  123. print("Passed. (Add more tests to be more sure!)")
  124.  
  125. def testMostFrequentLetter():
  126. print("Testing mostFrequentLetter...",end="")
  127. assert(mostFrequentLetter("ZgVhyaBbv.....") == "bv")
  128. assert(mostFrequentLetter("c D B a") == "abcd")
  129. assert(mostFrequentLetter(". ") == "")
  130. print("Passed. (Add more tests to be more sure!)")
  131.  
  132. def testAll():
  133. testJoinNames()
  134. testAreComplementary()
  135. testIsIntPalindrome()
  136. testAsciiTriangle()
  137. testMostFrequentLetter()
  138.  
  139. testAll()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement