-
Recent Posts
Recent Comments
Archives
Categories
Meta
Author Archives: Luis Vargas
#Mastery11
Comments Off on #Mastery11
Posted in Blogs, Syndicated, TC1014 Blogs
#Mastery10
Comments Off on #Mastery10
Posted in Blogs, Syndicated, TC1014 Blogs
#WSQ10
Lists
Create a program that asks the user for 10 numbers (floating point). Store those numbers in a list. Show to the user the total, average and standard deviation of those numbers.
#Luis Eduardo Vargas Victoria
#A01630086
#WSQ10
import statistics
def totalsum (m):
total = 0
for indice in range(len(m)):
total = total + m[indice]
return total
def average (m):
avg = total / 10.0
return avg
def standevi (m):
sd = statistics.stdev(l)
return sd
l=[]
x = 0
while (x < 10):
x = x + 1
n = float(input(“Give me a number: “))
l.append(n)
total = totalsum(l)
avg = average(l)
devi = standevi(l)
print (“No more values.”)
print (“Total sum: “, total)
print (“Average: “, avg)
print (“Stardard deviation: “, devi)
#WSQ09
Factorial Calculator
Create a program that asks the user for a non-negative integer (let’s call that number n) and display for them the value of n! (n factorial).
After showing them the answer, ask them if they would like to try another number (with a simple y/n response) and either ask again (for y) or quit the program and wish them a nice day (if they answered n).
#Luis Eduardo Vargas Victoria
#A01630086
#WSQ09
def factorial(n):
a = n
b = 1
while(a > 1):
b = b * a
a = a – 1
return b
import sys
op=”y”
while (op==”y”):
n=input(“Give me an integer number: “)
if (n.isdigit() == False ):
print (“Only integers”)
else:
n=int(n)
f=factorial(n)
if n < 0:
print (“Negative numbers are not accepted.”)
else:
if n==0:
print (“The factorial of 0 is 1.”)
else:
print(“The factorial of”,n,”is”,f)
op=input(“Want to try again? (y/n): “)
if (op == “n”):
print(“Have a nice day.”)
sys.exit()
#WSQ08
On To Functions
Write a function for each calculation. Each function should define two parameters (in this example of type int) and return the correct value as an integer as well.
You main program needs to ask the user for the input and then call each function to calculate the answer for each of the parts.
#Luis Eduardo Vargas Victoria
def sum(x,y) :
suma= x + y
return suma
def dif(x,y) :
resta= x – y
return resta
def pro(x,y) :
producto= x * y
return producto
def div(x,y) :
div= x / y
return div
def res(x,y) :
res= x % y
return res
x= int(input(“Dame el primer número: “))
y= int(input(“Dame el segundo número: “))
a=int(sum(x,y))
b=int(dif(x,y))
c=int(pro(x,y))
d=int(div(x,y))
e=int(res(x,y))
print (“La suma es: “,a)
print (“La resta es: “,b)
print (“La multiplicación es: “,c)
print (“La división es: “,d)
print (“El residuo es: “,e)
#Mastery07
Comments Off on #Mastery07
Posted in Blogs, Syndicated, TC1014 Blogs
#Mastery06
Comments Off on #Mastery06
Posted in Blogs, Syndicated, TC1014 Blogs
#Mastery05
Comments Off on #Mastery05
Posted in Blogs, Syndicated, TC1014 Blogs
#Mastery04
Comments Off on #Mastery04
Posted in Blogs, Syndicated, TC1014 Blogs
#Mastery02
Comments Off on #Mastery02
Posted in Blogs, Syndicated, TC1014 Blogs