def printImport(): print "Age", 42 # you can print with comma, will translate into space print "Age", # end with comma to prevent line break print 42 print 1,2,3 # will get space in between numbers import math as maa from math import sqrt as squareRoot print maa.sqrt(9) print squareRoot(9)
def printImport(): print "Age", 42 # you can print with comma, will translate into space print "Age", # end with comma to prevent line break print 42 print 1, 2, 3 # will get space in between numbers import math as maa from math import sqrt as squareRoot print maa.sqrt(9) print squareRoot(9)
def circumscribe(length, height): # Shamelessly adapted from https://github.com/misspellted/viewted/blob/main/geometry/shapes.py d(^_^)b if (length is None or length <= 0) and (height is None or height <= 0): raise ValueError( f"The dimensions were invalid for circumscribing: [{length} x {height}]" ) # We want to calculate the radius of the minimal circle that contains the # rectangle. # # Borrowing an ANSI/ASCII circle from https://ascii.co.uk/art/circle: # # (0, +R) # # ooo OOO OOO ooo # oOO OOo # oOO OOo # oOO OOo # oOO OOo # oOO+-------------------------------------+OOo # oOO | | OOo # oOO | | OOo # oOO | | OOo # oOO | | OOo # (-R, 0) oOO | | OOo (+R, 0) # oOO | | OOo # oOO | | OOo # oOO | | OOo # oOO | | OOo # oOO+-------------------------------------+OOo # oOO OOo # oO0 OOo # oOO OOo # oOO OOo # ooo OOO OOO ooo # # (0, -R) # # # Turns out, this has a name: a circumscribed cirlce of a rectangle: # https://www-formula.com/geometry/radius-circumcircle/radius-circumcircle-rectangle. # # Basically, the diagonals of the rectangle are the diameter of the circle. The diameter # can be calculated as the hypotenuse of a triangle in the rectangle, since both sides # are known (length, height): # # diameter = squareRoot(square(length) + square(height)) # # And then the radius is just half of that: # # radius = half(diameter) return Circle(squareRoot(length**2 + height**2) / 2)
def euclideanDistance(p1, p2): return squareRoot(abs((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2))
value = random.randint(70, 79) print(value) # take the form "from module_name import var", # then var can be used as if it were defined normally in your code. from math import pi # imports only the pi constant print(pi) # from the math module # trying to import an unavailable module will cause an ImportError # rename modules (eg. if they have long or confusing names) # by using "as" from math import sqrt as squareRoot # renaming "sqrt" print(squareRoot(250)) # using its new name in 2 examples print(squareRoot(pi)) # complete documentation of python's standard library can be found online # a way to install third party modules is a program called "pip" # these are stored on the Python package index (PyPI) # to install, go to the command Command Prompt and enter # "pip install library_name" print("scribble pad") def pebble(k): for j in range(k): print(j)
# Write a program that inputs the number of tiles and then prints out the maximum side length. You may assume that the number of tiles is less than ten thousand. from math import sqrt as squareRoot # input tiles = int(input('Enter the number of tiles: ')) # processing max_side_length = squareRoot(tiles) max_side_length = int(max_side_length) # output print('The largest square has side length', max_side_length)
""" Program that prints the numbers from 1 to 100, but for multiples of three print "Fizz" instead, for multiples of five print "Buzz" instead, and for multiples of both three and five print "FizzBuzz" 3 = "Fizz" 5 = "Buzz" 15 = "FizzBuzz" """ from math import sqrt as squareRoot print(squareRoot(25)) def fizzbuzz(start=1, end=100): for num in range(start,end+1): if num % 3 == 0 and num % 5 == 0: print("FizzBuzz") elif num % 3 == 0: print("Fizz") elif num % 5 == 0: print("Buzz") else: print(num) fizzbuzz()
def solveForX(e, n, z): return [e + squareRoot((z * e) / n), e - squareRoot((z * e) / n)]
# Create a Python program that calculates the distance between two points. There should be 4 integer inputs: x-coordinate and y-coordinate from the first point and x-coordinate and y-coordinate of the second point. ## Distance Solution from math import sqrt as squareRoot # input x_p1 = float(input('Enter coordinate x for point 1:')) y_p1 = float(input('Enter coordinate y for point 1:')) x_p2 = float(input('Enter coordinate x for point 2:')) y_p2 = float(input('Enter coordinate y for point 1:')) # processing difference_x = x_p2 - x_p1 difference_y = y_p2 - y_p1 distance = squareRoot(difference_x**2 + difference_y**2) # output print('The distance between the two points are:', distance, 'units.')