In: Computer Science
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 of one side equals the sum of the squares of the other two sides.
[FIGURE 3.5] The semantics of a while loop The following example is a short script that prompts the user for a series of numbers, computes their sum, and outputs the result. Instead of forcing the user to enter a definite number of values, the program stops the input process when the user simply presses the return or enter key. The program recognizes this value as the empty string. We first present a rough draft in the form of a pseudocode algorithm: set the sum to 0.0 input a string while the string is not the empty string convert the string to a float add the float to the sum input a string print the sum Note that there are two input statements, one just before the loop header and one at the bottom of the loop body. The first input statement initializes a variable to a value that the loop condition can test. This variable is also called the loop control variable. The second input statement obtains all of the other input val- ues, including one that will terminate the loop. Note also that the input must be received as a string, not a number, so the program can test for an empty string. If the string is not empty, we assume that it represents a number, and we convert it.
Q3 Modify the guessing-game program of Section 3.5 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.
side1=int(input("Enter side1: "))
side2=int(input("Enter side2: "))
side3=int(input("Enter side3: "))
if (side1==side2 and side2==side3): #if sides are equal
print("Equilateral triangle")
else:
print("Not an equilateral triangle")
l=[]
side1=int(input("Enter side1: "))
side2=int(input("Enter side2: "))
side3=int(input("Enter side3: "))
l.append(side1) #adding all values to a list
l.append(side2)
l.append(side3)
l.sort() #sorting list
c=l[2]*l[2] #calculating c^2=a^2+b^2
a=l[0]*l[0]
b=l[1]*l[1]
if (c==(a+b)): #if true
print("Right triangle")
else:
print("Not an right triangle")
summ=0.0
inp=input("Enter a number ") #taking string
while(inp!=""): #if the string is empty
summ=summ+(float(inp)) #convert string to float
inp=input("Enter a number ")
print("Sum: ",summ)
import random
number=int(input("Enter the guessed number(0-1000) ")) #taking
number
attempts=int(input("Enter attempts ")) #attempts
num=0
guessed_number=0
success=0
while(num!=attempts and number!=guessed_number): #iterates until
out of attempts
if guessed_number==number: #if number is found
success=1
break
if attempts==0:
guessed_number=random.randint(0,1001)
num+=1
else:
if guessed_number<number: #if
the number is greater than guessed number
guessed_number=random.randint(guessed_number,1001)
num+=1
else:
guessed_number=random.randint(0,guessed_number)
num+=1
if (guessed_number==number or success==1):
print("Number is :",guessed_number)
elif (success==0):
print("Sorry I lost")