Skip to content

Instantly share code, notes, and snippets.

@gilrg18
gilrg18 / YoSoy196
Created April 10, 2015 04:26
WSQ11
#Gilberto Rogel García A01630171 YOSOY196
def palindromes(x):
x1 = str(x)
x2 = x1[::-1]
x3 = int(x2)
if(x==x3):
return True
else:
return False
npalindromes = 0
#Gilberto Rogel García a01631071 Babylonian method
def bmethod(n):
x=n
y=0
while(x!= y):
y=x
#print ("y",y)
x=(n/x + x)/2
#print ("x",x)
return x
@gilrg18
gilrg18 / WSQ12
Created April 9, 2015 14:25
Greatest common divisor
#Gilberto Rogel García wsq12 greates common divisor
def gcd(x,y):
if(x==y):
res=x
elif(x>y):
res=gcd((x-y),y)
else:
res=gcd(x,(y-x))
return res
#Gilberto Rogel García wsq14 estimating e
def calculate_e(precision):
x=precision
e=(1+1/x)**x
return (e)
precision=int(input("Give me the number of decimal points of accuracy that you want: "))
print("The estimate e is: ",calculate_e(precision))
@gilrg18
gilrg18 / Lists
Created April 8, 2015 01:35
WSQ10
#Gilberto Rogel García A01630171
import statistics
def totalsum(list):
sum=0
for x in range (0,len(list)):
sum+=list[x]
return (sum)
def average(list):
avrg=totalsum(list)/10
return (avrg)
@gilrg18
gilrg18 / q2.py
Created March 24, 2015 18:30
Finding Threes
#Gilberto Rogel García a01630171
def find_threes (list):
sum=0
for x in range(0,len(list)):
if(list[x]%3==0):
#print(list[x])
sum+=list[x] #sum=sum+list[x]
return (sum)
print("This program gives you the sum of all the numbers divisible by 3 in a list")
@gilrg18
gilrg18 / q1.py
Created March 24, 2015 18:24
Triangles
#Gilberto Rogel García A01630171
def triangles(size):
for r in range(1,size+1):
for c in range(1,r+1):
print("t", end="")
print()
for r in range(size-1,0,-1):
for c in range(1,r+1):
print("t",end="")
print()
@gilrg18
gilrg18 / WSQ09
Last active August 29, 2015 14:16
Factorial
#Gilberto Rogel García A01630171
def fact(n):
n=n
a=1
while (n>1):
a=a*n
n=n-1
return (a)
x="y"
print("We will calculate the sum of integers in the range you provide")
result= 0
num1=int(input("Please give us the lower bound:"))
num2=int(input("Please give us the upper bound:"))
while num1>num2:
print ("User input error, please give us the numbers again")
num1=int(input("Please give us the lower bound:"))
num2=int(input("Please give us the upper bound:"))
@gilrg18
gilrg18 / Temperature
Created March 3, 2015 01:20
wsq05.py
f=int(input("Give me the temperature in Farenheit that you want to convert to Celsius: "))
c= 5*(f-32)/9
print("The temperature in Celsius is: ", int(c)) ###i put the c in a parenthesis using an int so it gives the value without decimals
if c>=100:
print ("Water boils at this temperature") ###note that you have to ident this line in order for this to work