Skip to content

Instantly share code, notes, and snippets.

@shinysu
Created September 2, 2020 11:02
Show Gist options
  • Save shinysu/c9eaad36df5337df5a7891696a9cc33e to your computer and use it in GitHub Desktop.
Save shinysu/c9eaad36df5337df5a7891696a9cc33e to your computer and use it in GitHub Desktop.
Day 4 programs
'''
print a string
'''
print("hello!")
'''
get an input from the user and print it
'''
name = input("Enter your name: ")
print("Hello", name)
'''
perform arithmetic operations
'''
num1 = int(input("First number: "))
num2 = int(input("Second number: "))
print("Sum = ", num1 + num2)
print("Difference = ", num1 - num2)
print("Product= ", num1 * num2)
print("Quotient= ", num1 / num2)
print("Remainder= ",num1 % num2)
print("Square of num1 = ", num1 ** 2)
'''
printing boolean values
'''
print(5 + 3 > 2 * 3)
print("Is this true? ", 5>10)
'''
get the radius of the circle and calculate the area of the the circle
round() - used to round of a number to two decimal points
'''
from math import pi
def find_area(radius):
area = pi * radius * radius
return area
input_radius = int(input("Enter radius: "))
area = find_area(input_radius)
print("Area of circle: ", round(area, 2))
'''
Build a temperature converter that can convert the temperature in celsius to fahrenheit
'''
def convert_temperature(temp_c):
temp_f = temp_c * (9 / 5) + 32
return temp_f
temp_c = float(input("Enter the temperature in celcius: "))
temp_f = convert_temperature(temp_c)
print("The temperature in Farenheit: ", temp_f,"F")
'''
temperature converter - converts the temperatue in celcius to farenheit and farenheit to celcius
Write a temperature converter that can get the temperature and units and convert it to the other metric.
'''
def convert_temperature(temp, unit):
if unit == 'c':
temp_new = temp * (9 / 5) + 32
unit = 'F'
elif unit == 'f':
temp_new = (temp - 32) * 5 / 9
unit = 'C'
return temp_new, unit
temp = float(input("Enter the temperature: "))
unit = input("Enter the unit: ")
temp_converted, unit = convert_temperature(temp, unit)
print("The temperature in Farenheit: ", temp_converted, unit)
'''
There are three types of triangles based on the sides.
An equilateral triangle is one in which all the sides are equal
An isosceles triangle has two equal sides
A scalene triangle has all sides of different length
Write a program that can get the three sides of a triangle and determine if the triangle is equilateral or isosceles or scalene
'''
x = int(input())
y = int(input())
z = int(input())
if x == y and x == z:
print("Equilateral triangle")
elif x == y or y == z or x == z:
print("Isosceles triangle")
else:
print("Scalene triangle")
'''
program that determines the distance between two given points
'''
from math import sqrt
def find_distance(x1, y1, x2, y2):
distance_sq = (x1 - x2) ** 2 + (y1 - y2) ** 2
distance = sqrt(distance_sq)
return distance
x1 = int(input("x1: "))
y1 = int(input("y1: "))
x2 = int(input("x2: "))
y2 = int(input("y2: "))
distance = find_distance(x1, y1, x2, y2)
print("Distance=", distance)
'''
Two circles touch each other if the distance between the centers of the circle is less than the sum of the radii of both
circles.
Write a program that gets the position of the center of the circles and the radius and determines if the circles
touch each other.
'''
from math import sqrt
def find_distance(x1, y1, x2, y2):
distance_sq = (x1 - x2) ** 2 + (y1 - y2) ** 2
distance = sqrt(distance_sq)
return distance
x1 = int(input("x1: "))
y1 = int(input("y1: "))
x2 = int(input("x2: "))
y2 = int(input("y2: "))
distance = find_distance(x1, y1, x2, y2)
r1 = int(input("Radius1: "))
r2 = int(input("Radius2: "))
if distance == r1 + r2:
print("Circles touch ech other")
elif distance > r1 + r2:
print("Circles do not touch each other")
else:
print("Circles overlap")
@Jayasuriya007
Copy link

ThankYou Mam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment