Skip to content

Instantly share code, notes, and snippets.

@shinysu
Last active October 30, 2020 05:53
Show Gist options
  • Save shinysu/3514affc046e85bf18fb6b6653a35b69 to your computer and use it in GitHub Desktop.
Save shinysu/3514affc046e85bf18fb6b6653a35b69 to your computer and use it in GitHub Desktop.
Simple 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")
'''
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)
1. Temperature converter - converts the temperatue in celcius to farenheit and farenheit to celcius.
Write a temperature converter that can get the temperature and units(celcius or farenheit)
and convert it to the other metric(farenheit or celcius respectively).
2. 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment