Created
September 2, 2020 11:02
-
-
Save shinysu/c9eaad36df5337df5a7891696a9cc33e to your computer and use it in GitHub Desktop.
Day 4 programs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
print a string | |
''' | |
print("hello!") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
get an input from the user and print it | |
''' | |
name = input("Enter your name: ") | |
print("Hello", name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
printing boolean values | |
''' | |
print(5 + 3 > 2 * 3) | |
print("Is this true? ", 5>10) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ThankYou Mam