Question

In: Computer Science

“Triangle Guessing” game in Python The program accepts the lengths of three (3) sides of a...

Triangle Guessing” game in Python

The program accepts the lengths of three (3) sides of a triangle as input . The program output should indicate if the triangle is a right triangle, an acute triangle, or an obtuse triangle.

  1. Make sure each side of the triangle is a positive integer. Use try/except for none positive integer input.
  2. validating the triangle. That is the sum of the lengths of any two sides of a triangle is greater than the length of the third side. Use try/except for invalid sides input.
  3. For any wrong input, tell the player what is wrong and asking to re-enter.
  4. Allow a player to play multiple times, for example, using a while loop. Remind the player what input to stop the game.
  5. user friendly one.
  6. add comments:
    1. Introduce/describe the program including the author, date, goal/purpose of the program
    2. Document every variable used at the program even the name is meaningful
    3. Explain/comment operation/activity/logic of your code. For example, “Checking whether the inputs are positive integers” and “Checking the validity the 3 lengths to see if they are able to form a triangle”
  7. Testing your program for all possible input and every of the 3 possible triangles

Solutions

Expert Solution

SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.




while True:
    try:
        # Check for numbers
        a,b,c = input('Enter 3 numbers (sides of a triangle) : ').split()
        a,b,c = int(a),int(b),int(c)
    except:
        print('Please Enter only Numbers..')
        continue

    # Only positive numbers are accepted
    if a<0 or b<0 or c<0:
        print('Invalid Numbers. Only Positive Numbers are accepted.')
        print('Please Try Again,,,!')
        continue
    # Validate triangle
    if not (a+b > c or b+c >a or a+c > b):
        print('Invalid Sides. These will not form a triangle.')
    else:
        if a>b and b>c:
            longest = a
            other_side1=b
            other_side2=c
        elif b>c:
            longest=b
            other_side1=a
            other_side2=c
        else:
            longest = c
            other_side1 = b
            other_side2 = a

    if longest**2 == other_side1**2 + other_side2**2:
        print('These sides form a right angled triangle.!!')
    elif longest**2 < other_side1**2 + other_side2**2:
        print('These sides form an acute triangle.!!')
    else:
        print('These sides form an obtuse triangle.!!')

    choice = input('Do you want to continue:(Y/N)')
    if not choice=='Y':
        break

print('Bye!!')




=======================

SCREENSHOT:

OUTPUT SAMPLE:


Related Solutions

Write a program that accepts the lengths of three sides of a triangle as inputs. The...
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. Use The triangle is a right triangle. and The triangle is not a right triangle. as your final outputs. An example of the program input...
You are asking to develop a “Triangle Guessing” game in Python for the assignment. The program...
You are asking to develop a “Triangle Guessing” game in Python for the assignment. The program accepts the lengths of three (3) sides of a triangle as input from a player. The program output should indicate whether the triangle is a right triangle, an acute triangle, or an obtuse triangle. 1.Tips to help you for this assignment: Make sure each side of the triangle is a positive integer. Use try/except for none positive integer input. 2. Validating the triangle. That...
(PYTHON) Write aprogram that prompts user to enter three sides of a triangle....
(PYTHON) Write a program that prompts user to enter three sides of a triangle. The program should determine if the three sides can form a triangle. If the three sides can form a triangle, then determine the type of the triangle.There are three types of triangles: Equilateral triangle (all 3 sides are equal) Isosceles triangle (two sides are equal, the third side is of a different length) Scalene triangle (all 3 sides are of different lengths)   The program should...
Please use the python 3.7 for this assigments Q1 Write a program that accepts the lengths...
Please use the python 3.7 for this assigments Q1 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. Q2 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...
Write a program using Python that allows the user to play a guessing game (please provide...
Write a program using Python that allows the user to play a guessing game (please provide a picture of code so it is easier to read). The game will choose a "secret number", a positive integer less than 10000. The user has 10 tries to guess the number. Requirements: Normally, we would have the program select a random number as the "secret number". However, for the purpose of testing your program (as well as grading it), simply use an assignment...
I need to write PYTHON program which is like a guessing game using randint function which...
I need to write PYTHON program which is like a guessing game using randint function which is already done, the user has to guess a number between 1 and 1000 and the game musn't end until you guess the number, if you input a smaller number you must get hints, the same goes if your input is bigger than the wining number , also you must get notified if you repeat a number (example, you pick 1 and in the...
Random Number Guessing Game (python) *use comments Write a program guess.py that generates a random number...
Random Number Guessing Game (python) *use comments Write a program guess.py that generates a random number in the range of 1 through 20, and asks the user to guess what the number is. If the user's guess is higher than the random number, the program should display "Too high, try again." If the user's guess is lower than the random number, the program should display "Too low, try again." If the user guesses the number, the application should congratulate the...
Assignment: Write an interactive C++·program to determine a type of a triangle based on three sides....
Assignment: Write an interactive C++·program to determine a type of a triangle based on three sides. Have a user input the length of three sides of a triangle. Allow the user to enter the sides in any order. Determine if the entered sides form a valid triangle. The triangle may not have negative sides. The sum of any two sides must be greater than the third side to form a triangle. Determine if the entered sides are part of a...
Write a program that asks the user for the lengths of the sides of a rectangle....
Write a program that asks the user for the lengths of the sides of a rectangle. Again, check for valid input and exit with an error msg if you don’t get it. Testing: use some known values to confirm that the calculations are correct. E.g. 3 – 4 - 5 triangle >> 3 X 4 rectangle Then print • The area and perimeter of the rectangle • The length of the diagonal (use the Pythagorean theorem). This question should be...
Argument A Since all triangles have three sides, and an isosceles triangle is a triangle, it...
Argument A Since all triangles have three sides, and an isosceles triangle is a triangle, it follows that an isosceles triangle has three sides. Argument a is: inductive/deductive; valid/invalid/strong/weak; sound/unsound/cogent/uncogent? Argument B There is a large crack in Philadelphia's Liberty Bell. From this, we can conclude that there was a defect in the bell's craftsmanship. Argument B is: inductive/deductive; valid/invalid/strong/weak; sound/unsound/cogent/uncogent? Argument C Paleontologists now agree that the Tyrannosaurus Rex was actually a peaceful, plant-eating dinosaur. Therefore, it is probably...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT