Buscar

Fernando's blog

Programming class

Categoría

QUIZ

Quiz11

For this quiz we had to make two programms. One that calculate the value o e with the given accuracy by the user and a program that search for the word banana in a text file.

I struggled with the file question since i dont know how to use properly the .split() very well but still i did my best effort.

Here is my code of the first question: https://github.com/sabaldaba/TC101/blob/master/Question1-quiz

And the second one: https://github.com/sabaldaba/TC101/blob/master/question2-quiz11

Quiz08

I’m having a lot of troubles with this, specially because i have not time enough. This will be a reminder to myself that i should never let things to the last minute.

The code i wrote is this, and i still cant find the problem. Still i hope i’ll find out with Ken what my problem is so i can come back and fix the entry.

#Jorge Fernando Saldaña Cabal
#A01350730

def main():
def dot_product(a,b):
print(‘Lest get the dot product of two lists.’)
num = input(‘Enter number(s), use «,» to separate them: ‘).split(‘,’)
return [int(n) for n in num]
num2 = input(‘Enter number(s), use «,» to separate them: ‘).split(‘,’)
return [int(j) for j in num2]

if (len(num) > len(num2)):
big = num
else:
big = num2

res = 0
for i in range(len(big)):
t = num[i] * num2[i]
res = res + t
return(print(res))

I’m getting a sintax error in ‘    return [int(n) for n in num]’

I’ll come back and fix this.

QUIZ7

P1.-

#Jorge Fernando Saldaña Cabal
#A01350730

import math
def distance(x1,y1,x2,y2):
z1=x1-x2
z1=z1**2
z2=y1-y2
z2=z2**2
res=math.sqrt(z1+z2)
return(res)

def main():
x1=int(input(‘Type x1: ‘))
y1=int(input(‘Type y1: ‘))
x2=int(input(‘Type x2: ‘))
y2=int(input(‘Type y2: ‘))
print(‘The distance between those points is: ‘, distance(x1,y1,x2,y2))
return(0)

main()

P2.-

#Jorge Fernando Saldaña Cabal
#A01350730

def fibonacci(a):
x=1
y=0
for i in range(a-1):
z = y + x
y = x
x = z
if (a == 0):
z=0
elif (a==1):
z=1
return(z)

def main():
a =int(input(‘Until which number you want to calculate the fibonacci serie: ‘))
print(‘The fibonacci serie until’, a, ‘is: ‘, fibonacci(a))
return(0)

main()

QUIZ#06

P1.-
#Fernando Saldaña
#A01350730

def superpower (a,b):
ans = 1
for i in range(b):
ans = ans * a
return (ans)

print («Hey lets make some math»)
x = int(input(«Please type a non-negative number so we can raised it: «))
y = int(input(«please type a non-negative number so we can use it as exponent: «))

print(x, ‘raised to the’, y, ‘power is: ‘, superpower(x,y))



P2.-
#Fernando Salaña
#A01350730

def stars (a):
ans = »
for i in range(a):
ans = ‘*’ + ans
return (ans)

x = int(input(‘Type how many stars you want to see: ‘))
print (stars(x))

Crea un blog o un sitio web gratuitos con WordPress.com.

Subir ↑