Skip to content

Instantly share code, notes, and snippets.

num1 = int(input("Give me a number: ")) #Asks the user for a number
num2 = int(input ("Give me another number: ")) #Asks the user for another number
suma = num1+num2 #this is the variable for the sum of two numbers
resta= num1-num2 #this is the variable for the difference of two numbers
multi= num1*num2 #this ios the variable for the product of two numbers
@gilrg18
gilrg18 / helloworld
Created March 3, 2015 01:00
Hello World
print ("hello world")
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
@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"
@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 / 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 / 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)
#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 / 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