1. How to determine if a Triangle exist in python.
Code :
print("Insert lenght of proposed triangle: ")
x = float(input("x = "))
y = float(input("y = "))
z = float(input("z = "))
if x+y>z and x+z>y and y+z>x:
print("The triangle of xyz exist")
else:
print("The triangle does not exist")
Output :
2. How to check for Leap year in python.
Code :
yr = int(input("Insert any year to check for leap year: "))
if yr%4 == 0:
print("This is a leap year!")
else:
print("This is not a leap year!")
Output :
3. How to check if a point belongs to Circle in python.
Code :
import math
x = float(input("Insert point x: "))
y = float(input("Insert point y: "))
r = float(input("Insert the radius: "))
hypotenuse = math.sqrt(pow(x,2) + pow(y,2))
if hypotenuse <= r:
print("The point belongs to circle.")
else:
print("The point does not belong to circle.")
Output :
4. How to create quadratic Equation in python.
Code :
from math import sqrt
x = float(input("Insert x = "))
y = float(input("Insert y = "))
z = float(input("Insert z = "))
a = y*y-4*x*z
if a>0:
x1 = (-y + sqrt(a))/(2*x)
x2 = (-y - sqrt(a))/(2*x)
print("x1 = %.2f; x2 = %.2f" % (x1,x2))
elif a==0:
x1 = -y/(2*x)
print("x1 = %.2f" % x1)
else:
print("No roots exist")
Output :
5.How to make ques of Random number in python.
Code :
from random import randint
guess_num = randint(1,100)
user_input = 0
trial_period = 1
while guess_num != user_input:
print("The trial no %d: " % trial_period, end='')
user_input = int(input())
if user_input < guess_num:
print("The input number is less")
elif user_input > guess_num:
print("The input number is much")
else:
print("Kudos! The right guess...")
trial_period += 1
Output :
0 Comments