Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

finding third angle

print ("finding the third angle of triangle")
first=float(input("enter the first angle:\n"))
second=float(input("enter the second angle:\n"))
angle= 180 - round(first + second,2)
print ("the third angle is",angle)

Execute Python-3 Online

# Adventure Game Alyssa Farrah Bancale
import random
print("You are lost underground in a maze of tunnels.")
dangerTunnel = random.randint(1,2)
tunnelChoice = int(input("Choose tunnel 1 or tunnel 2: "))

triangles

# Hello World program in Python
    
print ("assesment")
print ("area of a triangle")
A  = float(input("enter angle A in degrees: \n"))
B  = float(input("enter angle B in degrees: \n"))
C  = round(180-A - B ,1)
print ("missing angle is",C,"degrees")

t,tttttriangle

# Hello World program in Python
    
print ("Assessment")
print ("angles of a triangle")
A = float(input("enter angle A in degrees:\n "))
B = float(input("enter angle B in degrees:\n"))
C = round(180-A - B ,1)
print ("missing angle is",C,"degrees")

Triangle angles

print("Angles of a triangle")
D = float(input("D-A+B\n"))
A = float(input("enter A in degrees\n"))
B = float(input("enter B in degrees\n"))
C = round(A + B - D,1)
print("angle C is",C,"degrees")

Execute Python-3 Online

print("angles of a triangle")
a=float(input("input angle in degrees:\n"))
b=float(input("input angle in degrees:\n"))
c=round(180-b-a,1)
if a==b and a==c and b==c:
    print ("this is a equilateral triangle")
elif a==b or a==c or c==b:
    print ("this is a isosceles triangle")
elif a==90 or b==90 or c==90:
        print ("this is a right triangle")
elif a==0 or b==0 or c==0:
    print ("this triangle is incorrect")
else:
    print ("this is a scalene triangle")

lmkpokl

# Hello World program in Python
    
print ("Hello World!");
jhhchdjglfxh

Execute Python-3 Online

# Hello World program in Python
    
print("Angles of a triangle...")
a = float(input("Enter angle a in degrees:\n"))
b = float(input("Enter angle b in degrees:\n"))
result = (180 - a - b)
print("Missing number is",result,"degrees")
if angle a == angle b == result:
    print("This is an equilateral triangle")
elif angle a == angle b or angle a == result or angle b == result
    print("This is an isosceles triangle")
elif no angles are the same:
    print("This is a scalene triangle")
else angle a or b or c = 90:
    print("This is a right angle triangle")

kevin word game

#Wacky Word Game program

#Part 1: Request the input words.
first_name = input("Type your name, and select enter: ")
print("")
print("Hello " + first_name + ". Let's play a game.")
print("")
adjective1 = input("Tell me an adjective, and select enter. ")
noun1 = input("Tell me a noun (plural), and select enter. ")
noun2 = input("Tell me another noun (plural), and select enter. ")
adjective2 = input("Tell me another adjective, and select enter. ")

#Part 2: Print the poem.
print(first_name + "'s Wacky Word Game")
print("")
print("Roses are " + adjective1)
print(noun1 + " are blue")
print(noun2 + " are " + adjective2)
print("And so are you!")

Zelle Ch. 6

# Zelle Ch. 6 Exercises

def main():
    print ("No main() defined");


# Ex. 11

def squareEach(nums): # squares each number in list nums
    for index,number in enumerate(nums):
        nums[index] = number ** 2

def main():
    someList = [3, 6, 7, 2, 16, 5]
    print("Original: {}".format(someList))
    squareEach(someList)
    print("New: {}".format(someList))
    

# Ex. 12

def sumList(nums): # returns the sum of the numbers in list nums
    listSum = 0
    for number in nums:
        listSum += number
    return listSum

def main():
    someList = [3, 6, 7, 2, 16, 5] # sum = 39
    print("The total of all the numbers in the list is {}.".format(sumList(someList)))


# Ex. 13

def toNumbers(strList): # list of numbers represented as strings converted to numbers
    for index,string in enumerate(strList):
        strList[index] = float(string)

def main():
    strList = ["23", "1.2345", "-5", "0.6"]
    print("Original: {}".format(strList))
    toNumbers(strList)
    print("New: {}".format(strList))



# Ex. 14 - Use the functions from the previous three problems to implement a
# program that computes the sum of the squares of numbers read from a file.
# Your program should prompt for a file name and print out the sum of the
# squares of the values in the file.  Hint: Use readlines()

def main():
    fname = "ch6ex14input.txt"
    infile = open(fname,"r")
    
    numList = infile.readlines()
    # numList = ["2\n","5\n","6\n"] # test string
    toNumbers(numList)
    squareEach(numList)
    print("The sum of the squares of numbers in the input file: {}".format(sumList(numList)))



# Ex. 15 - Write and test a function to meet this specification.
#
# drawFace(center,size,win) center is a Point, size is an int, and win is a
# GraphWin. Draw a simple face of the given size in win.
#
# Your function can draw a simple smiley (or grim) face.  Demonstrate the
# function by writing a program that draws several faces of varying size in a
# single window.

from graphics import *

def drawFace(center, size, win):
    faceColor = "yellow"
    face = Circle(center, size)
    face.setFill(faceColor)
    face.draw(win)
    
    # start with a circle for the smile
    smile = Circle(center, 3 * size / 5)
    smile.setFill(faceColor)
    smile.setOutline("red")
    smile.setWidth(3)
    smile.draw(win)
    # mask out the top of the circle to leave an arc
    p1 = Point(center.getX() - 13 * size / 20, center.getY() - 3 * size / 10)
    p2 = Point(center.getX() + 13 * size / 20, center.getY() + 13 * size / 20)
    smileMask = Rectangle(p1,p2)
    smileMask.setFill(faceColor)
    smileMask.setOutline(faceColor)
    smileMask.draw(win)
    
    # draw the eyes
    p1 = Point(center.getX() - size / 10, center.getY() - size / 5)
    p2 = Point(center.getX() + size / 10, center.getY() + size / 10)
    rightEye = Oval(p1, p2)
    rightEye.move(2 * size / 5, -2 * size / 5)
    rightEye.setFill("white")
    rightEye.draw(win)
    leftEye = rightEye.clone()
    leftEye.move(-4 * size / 5, 0)
    leftEye.draw(win)

def main():
    win = GraphWin("Too Many Smileys", 400, 400)
    win.setCoords(0,0,15,15)
    drawFace(Point(1.1,1.1), 1, win)
    drawFace(Point(4,4), 2, win)
    drawFace(Point(10,10), 4, win)
    
    win.getMouse()


# Ex. 16 - Use your drawFace function from the previous exercise to write
# a photo anonymizer.  This program allows a user to load an image file (such
# as a PPM or GIF) and to draw cartoon faces over the top of existing faces in
# the photo.  The user first inputs the name of the file containing the image.
# The image is displayed and the user is asked how many faces are to be
# blocked.  The program then enters a loop for the user to click on two points
# for each face: the center and somewhere on the edge of the face (to
# determine the size of the face).  The program should then draw a face in
# that location using the drawFace function.
#
# Hints: section 4.8.4 describes the image-manipulation methods in the graphics
# library.  Display the image centered in a GraphWin that is the same width and
# height as the image, and draw the graphics into this window.  You can use
# a screen capture utility to save the resulting images.

import math

def main():
#     fname = input("Enter the name of the image file to anonymize: ")
	fname = "104_0703.gif"
	numberOfFaces = 2 
	image = Image(Point(0, 0), fname)
	w = image.getWidth()		# 256
	h = image.getHeight()		# 192
	image.move(w / 2, h / 2)
	win = GraphWin("Anonymize", w, h)
	win.setCoords(0,0,w,h)
	image.draw(win)
    
    # now for the fun stuff:
	for i in range(numberOfFaces):
		center = win.getMouse()
		edge = win.getMouse()
		r = math.sqrt((center.getX() - edge.getX()) ** 2 + (center.getY() - edge.getY()) ** 2)
		drawFace(center, r, win)
    
    # wait before closing
	win.getMouse()
    

# Ex. 17 - Write a function to meet this specification.
#
# moveTo(shape,newCenter) shape is a graphics object that supports the getCenter
# method and newCenter is a point. Move shape so that newCenter is its center.
# 
# Use your function to write a pragram that draws a circle and then allows the
# user to click the window 10 times.  Each time the user clicks, the circle
# is moved where the user clicked.

from graphics import *

def moveTo(shape, newCenter):
    dx = newCenter.getX() - shape.getCenter().getX()
    dy = newCenter.getY() - shape.getCenter().getY()
    shape.move(dx, dy)

def changeFillColor(shape, colors):
        colors[0] = (colors[0] + 63) % 256
        colors[1] = (colors[1] + 31) % 256
        colors[2] = (colors[2] + 15) % 256
        shape.setFill(color_rgb(colors[0], colors[1], colors[2]))

def changeOutlineColor(shape, colors):
        colors[0] = (colors[0] + 31) % 256
        colors[1] = (colors[1] + 15) % 256
        colors[2] = (colors[2] + 63) % 256
        shape.setOutline(color_rgb(colors[0], colors[1], colors[2]))

def main():
    winSize = 400
    win = GraphWin("Wandering Circle", winSize, winSize)
    win.setBackground("gray")
    win.setCoords(-10,-10,10,10)
    
    circle = Circle(Point(0,0), 1)
    fillColor = [31, 225, 196]          # "darkviolet"  #9400D3
    outlineColor = [224, 255, 30]       # "deeppink"    #FF1493
    changeFillColor(circle, fillColor)
    changeOutlineColor(circle, outlineColor)
    circle.setWidth(3)
    circle.draw(win)
    
    for i in range(10):
        moveTo(circle, win.getMouse())
        changeFillColor(circle, fillColor)
        changeOutlineColor(circle, outlineColor)
    
    win.getMouse()






































# class Image(GraphicsObject):

#     idCount = 0
#     imageCache = {} # tk photoimages go here to avoid GC while drawn 
    
#     def __init__(self, p, *pixmap):
#         GraphicsObject.__init__(self, [])
#         self.anchor = p.clone()
#         self.imageId = Image.idCount
#         Image.idCount = Image.idCount + 1
#         if len(pixmap) == 1: # file name provided
#             self.img = tk.PhotoImage(file=pixmap[0], master=_root)
#         else: # width and height provided
#             width, height = pixmap
#             self.img = tk.PhotoImage(master=_root, width=width, height=height)

#     def __repr__(self):
#         return "Image({}, {}, {})".format(self.anchor, self.getWidth(), self.getHeight())
                
#     def _draw(self, canvas, options):
#         p = self.anchor
#         x,y = canvas.toScreen(p.x,p.y)
#         self.imageCache[self.imageId] = self.img # save a reference  
#         return canvas.create_image(x,y,image=self.img)
    
#     def _move(self, dx, dy):
#         self.anchor.move(dx,dy)
        
#     def undraw(self):
#         try:
#             del self.imageCache[self.imageId]  # allow gc of tk photoimage
#         except KeyError:
#             pass
#         GraphicsObject.undraw(self)

#     def getAnchor(self):
#         return self.anchor.clone()
        
#     def clone(self):
#         other = Image(Point(0,0), 0, 0)
#         other.img = self.img.copy()
#         other.anchor = self.anchor.clone()
#         other.config = self.config.copy()
#         return other

#     def getWidth(self):
#         """Returns the width of the image in pixels"""
#         return self.img.width() 

#     def getHeight(self):
#         """Returns the height of the image in pixels"""
#         return self.img.height()

#     def getPixel(self, x, y):
#         """Returns a list [r,g,b] with the RGB color values for pixel (x,y)
#         r,g,b are in range(256)

#         """
        
#         value = self.img.get(x,y) 
#         if type(value) ==  type(0):
#             return [value, value, value]
#         elif type(value) == type((0,0,0)):
#             return list(value)
#         else:
#             return list(map(int, value.split())) 

#     def setPixel(self, x, y, color):
#         """Sets pixel (x,y) to the given color
        
#         """
#         self.img.put("{" + color +"}", (x, y))
        

#     def save(self, filename):
#         """Saves the pixmap image to filename.
#         The format for the save image is determined from the filname extension.

#         """
        
#         path, name = os.path.split(filename)
#         ext = name.split(".")[-1]
#         self.img.write( filename, format=ext)


main()

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.