Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. import math
  2.  
  3. #####
  4. #Question 1
  5. #####
  6.  
  7. def pythagorean_pair(a, b):
  8. """
  9. (integer, integer)-> (boolean)
  10.  
  11. Function intakes two integer values(a, b) and checkes if there is
  12. an integer (c) which is the the square root of the sum of the squares of the
  13. integer variables(a,b). . If there is a integer (c) which
  14. satisfies the given equation: c = sqrt(a^2+b^2), then the function returns
  15. true. Otherwise, the function will return false.
  16.  
  17. """
  18. c = math.sqrt(a**2 + b**2)
  19. return c % 1 == 0
  20.  
  21.  
  22. #####
  23. #Question 2
  24. #####
  25.  
  26. def mh2kh(s):
  27. """
  28. (number) -> (float)
  29.  
  30. Function intakes a numerical value that represents speed in miles/hour (s)
  31. and converts the given speed(s) to kilometers/hour(kh) and returns that float
  32. value.
  33.  
  34. """
  35. kh = s * 1.60934
  36. return kh
  37.  
  38.  
  39. #####
  40. #Question 3
  41. #####
  42.  
  43. def in_out(xs, ys, side):
  44. """
  45. (number, number, number) -> (boolean)
  46.  
  47. Given the bottom left coordinate (xs, ys) of a square and a side length,
  48. the function will check if the a query coordinate given by the user of the
  49. function will lie in inside or outside the square. If query point is inside the given square, the function
  50. will print True. If the query point is outside the square the fucntion will print false. Returns None.
  51.  
  52. Precondition: the square side length given as 'side' is a positive number
  53. """
  54. input_x = float(input("Enter a number for the x coordinate of a query point:"))
  55. input_y = float(input("Enter a number for the y coordinate of a query point:"))
  56. print(input_x >= xs and input_x <= xs + side and input_y >= ys and input_y <= ys + side)
  57.  
  58.  
  59. #####
  60. #Question 4
  61. #####
  62.  
  63. def safe(n):
  64. """
  65. (integer) -> (boolean)
  66.  
  67. Function determines whether the given integer(n) is safe or not. Being safe means not containing the digit 9 and
  68. not being divisible by 9. The function returns true if the argument(n) is safe, and false if the argument(n) isn't safe.
  69.  
  70. Precondition: the given argumemt(n) must be a non-negative integer with at most 2 digits.
  71. """
  72. div_9 = n % 9 == 0
  73. first_dig_is_9 = n // 10 == 9
  74. last_dig_is_9 = n % 10 == 9
  75. return not(div_9 or first_dig_is_9 or last_dig_is_9)
  76.  
  77.  
  78. #####
  79. #Question 5
  80. #####
  81.  
  82. def quote_maker(quote, name, year):
  83. """
  84. (string, string, anything) -> (string)
  85.  
  86. Function will take in a quote, name of the author of the quote and the year it was said in. The year can be spelled out,
  87. or given as any integer or float. The function will return a string combining all the arguments into a comprehendable sentence.
  88.  
  89. precondition: quote and name should be strings ******** year int?
  90. """
  91. return f"In {year}, a person called {name} said \"{quote}\""
  92.  
  93.  
  94. #####
  95. #Question 6
  96. #####
  97.  
  98. def quote_displayer():
  99. """
  100. () -> (None)
  101.  
  102. This function takes in no arguments. Functions prompts user to enter a quote, the name of the person who said this quote, and
  103. the year this quote was said in. Will return None, but will print out the quote, name and year in a comprehendable sentence.
  104. """
  105. quote = input("Give me a quote: ")
  106. name = input("Who said that? ")
  107. year = input("What year did he/she say that? ")
  108. print (quote_maker(quote, name, year))
  109.  
  110.  
  111. #####
  112. #Question 7
  113. #####
  114.  
  115. def rps_winner():
  116. """
  117. () -> (None)
  118.  
  119. Function will prompt user for the choice of player 1and then the choice of player 2. THe function will then print the results
  120. of the game.Returns None.
  121.  
  122. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement