Python Assignments Triangle and Guessing Number

These projects must be done in the latest version of IDLE:

  1. Write a program that accepts the lengths of three sides of a triangle as inputs. The program output should indicate whether or not the triangle is an equilateral triangle.
  2. Write a program that accepts the lengths of three sides of a triangle as inputs. The program output should indicate whether or not the triangle is a right triangle.
    Recall from the Pythagorean theorem that in a right triangle, the square of one side equals the sum of the squares of the other two sides.
  3. Modify the guessing-game program of Section 3.5, listed below, so that the user thinks of a number that the computer must guess. The computer must make no more than the minimum number of guesses.

    (Code is as follows)

    import random
    smaller = int(input("Enter the smaller number: "))
    larger = int(input("Enter the larger number: "))
    myNumber = random.randit(smaller, larger)
    count = 0
    while True:
       count += 1
       if userNumber < myNumber:
           print("Too small")
       elif userNumber > myNumber:
           print("Too large")
       else:
           print("Congratulations! You've got it in", count, "tries!")
           break 
    



This slideshow requires JavaScript.



This assignment includes three python programs

  • Attachments
  • Preview random excerpt
    a = 
    xxxxx
    (input(
    xxxxxx
    the length
    xx
    first side of a triangle:
    x
    )) b = float(input(
    xxxxxx
    xxx
    xxxxxx
    xx
    second side
    xx
    a triangle: ")) c = float(input("Enter the length
    xx
    third side of a triangle:
    x
    )) if (
    x
    ==
    x
    and b == c):
    xxxxx
    ("The triangle is a equilateral triangle") else: print("The
    xxxxxxxx
    is not
    x
    equilateral triangle")
    Preview random excerpt
    xxxxxxx = xxx(xxxxx("xxxxx xxx xxxxxxx xxxxxx: "))
    xxxxxx = xxx(xxxxx("xxxxx xxx xxxxxx xxxxxx: "))
    xxxxx("xxx xxxx xxxxxx xx x xxxxxx xx xxxxx [" + xxxxxx(xxxxxxx) + ", " + xxxxxx(xxxxxx) + "]")
    xxxxx = 0
    xxxxx xxxx:
    xxxxx
    +=
    x
    xxxxx
    =
    xxx
    ((smaller +
    xxxxxx
    ) /
    x
    )
    xxxxx
    (
    xxxxxxxxx
    guess is:
    x
    +
    xxxxxx
    (guess))
    xxxxx
    =
    xxx
    (input("Please enter 0/
    x
    if guesses number too low,
    xxx
    xxxx
    xx
    enter 2 if
    xxx
    xxxxxxx
    is
    xxxxxxx
    : "))
    xx
    state ==
    x
    :
    xxxxx
    ("Too small")
    xxxxxxx
    = guess elif
    xxxxx
    ==
    x
    :
    xxxxxx
    =
    xxxxx
    xxxxx
    ("Too large")
    xxxx:
    xxxxx("xxxxxxxxxxxxxxx! xxx'xx xxx xx xx", xxxxx, "xxxxx!")
    xxxxx
    - - - more text follows - - -
    Preview random excerpt
    a = float(
    xxxxx
    ("Enter
    xxx
    xxxxxx
    xx
    first side of a
    xxxxxxxx
    :
    x
    ))
    x
    =
    xxxxx
    (
    xxxxx
    ("Enter the length of
    xxxxxx
    xxxx
    of a triangle:
    x
    )) c =
    xxxxx
    (input("Enter the length of third
    xxxx
    of a triangle: ")) if ((
    x
    *
    x
    ==
    x
    *b +
    x
    *c) or (a*a +
    x
    *b == c*c)
    xx
    (a*
    x
    + c*c ==
    x
    *
    x
    )):
    xxxxx
    ("The triangle is a right
    xxxxxxxxx
    ) else: print("The triangle is not a
    xxxxx
    triangle")



Purchasing Instruction
List Price: $19
Buy Now

Add to Cart