Skip to content

Instantly share code, notes, and snippets.

@jerryalfs
jerryalfs / With Python 3.4
Created January 31, 2016 10:12
Area Of A Arbitary Triangle
#How to calculate area of an arbitary triangle
import math
a = input("Enter value a : ")
a = float(a)
b = input("Enter value b : ")
b = float(b)
c = input("Enter the degree : ")
c = float(c)
c = math.radians(c)
area = 1/2 * a * b * math.sin(c)
@jerryalfs
jerryalfs / Area Equilateral Triangle Python
Created January 31, 2016 09:48
Calculate Area Equilateral Triangle With Python
#Area of an equilateral triangle
import math
#to use math function must import lib math
h = input("Enter the height of equilateral triangle : ")
#to input value height and store to variable h
h = float(h)
#convert value have input to be float
a = (h**2 * math.sqrt(3))/3
#formula to calculate the area
print ("The area of an equilateral triangle : ",a)
@jerryalfs
jerryalfs / Area Trapezoid
Created January 31, 2016 09:39
Calculate Area Of Trapezoid With Python
#Area Of A Trapezoid
h = input("Enter the height of the trapezoid : ")
#input value height of the trapezoid
h = float(h)
#convert h into float value
lb = input("Enter the lenght of the bottom base : ")
#input value lenght bottom base
lb = float(lb)
#convert lenght bottom base to float value
lt = input("Enter the lenght of the top base : ")
@jerryalfs
jerryalfs / python 3.4
Created January 31, 2016 09:29
How to close pygame after press x button
from sys import exit
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
#PUT THE FOLLOWING CODE AT THE END OF PYGAME
@jerryalfs
jerryalfs / finish.py
Created January 31, 2016 09:25
Camel Game With Python
print("Welcome to Camel!","\nYou have stolen a camel to make your way across the great Mobi desert.","\nThe natives want their camel back and are chasing you down! Survive your","\ndesert trek and out run the natives.")
import random
done = False
miles_traveled = 0
thirst = 0
camel_tired = 0
natives_traveled = -20
drink = 5
natives_up = random.randrange(0, 10)
full_speed = random.randrange(10, 20)