Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- #####
- #Question 1
- #####
- def pythagorean_pair(a, b):
- """
- (integer, integer)-> (boolean)
- Function intakes two integer values(a, b) and checkes if there is
- an integer (c) which is the the square root of the sum of the squares of the
- integer variables(a,b). . If there is a integer (c) which
- satisfies the given equation: c = sqrt(a^2+b^2), then the function returns
- true. Otherwise, the function will return false.
- """
- c = math.sqrt(a**2 + b**2)
- return c % 1 == 0
- #####
- #Question 2
- #####
- def mh2kh(s):
- """
- (number) -> (float)
- Function intakes a numerical value that represents speed in miles/hour (s)
- and converts the given speed(s) to kilometers/hour(kh) and returns that float
- value.
- """
- kh = s * 1.60934
- return kh
- #####
- #Question 3
- #####
- def in_out(xs, ys, side):
- """
- (number, number, number) -> (boolean)
- Given the bottom left coordinate (xs, ys) of a square and a side length,
- the function will check if the a query coordinate given by the user of the
- function will lie in inside or outside the square. If query point is inside the given square, the function
- will print True. If the query point is outside the square the fucntion will print false. Returns None.
- Precondition: the square side length given as 'side' is a positive number
- """
- input_x = float(input("Enter a number for the x coordinate of a query point:"))
- input_y = float(input("Enter a number for the y coordinate of a query point:"))
- print(input_x >= xs and input_x <= xs + side and input_y >= ys and input_y <= ys + side)
- #####
- #Question 4
- #####
- def safe(n):
- """
- (integer) -> (boolean)
- Function determines whether the given integer(n) is safe or not. Being safe means not containing the digit 9 and
- not being divisible by 9. The function returns true if the argument(n) is safe, and false if the argument(n) isn't safe.
- Precondition: the given argumemt(n) must be a non-negative integer with at most 2 digits.
- """
- div_9 = n % 9 == 0
- first_dig_is_9 = n // 10 == 9
- last_dig_is_9 = n % 10 == 9
- return not(div_9 or first_dig_is_9 or last_dig_is_9)
- #####
- #Question 5
- #####
- def quote_maker(quote, name, year):
- """
- (string, string, anything) -> (string)
- 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,
- or given as any integer or float. The function will return a string combining all the arguments into a comprehendable sentence.
- precondition: quote and name should be strings ******** year int?
- """
- return f"In {year}, a person called {name} said \"{quote}\""
- #####
- #Question 6
- #####
- def quote_displayer():
- """
- () -> (None)
- This function takes in no arguments. Functions prompts user to enter a quote, the name of the person who said this quote, and
- the year this quote was said in. Will return None, but will print out the quote, name and year in a comprehendable sentence.
- """
- quote = input("Give me a quote: ")
- name = input("Who said that? ")
- year = input("What year did he/she say that? ")
- print (quote_maker(quote, name, year))
- #####
- #Question 7
- #####
- def rps_winner():
- """
- () -> (None)
- Function will prompt user for the choice of player 1and then the choice of player 2. THe function will then print the results
- of the game.Returns None.
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement