This commit is contained in:
Oystein Kristoffer Tveit 2020-09-14 16:36:09 +02:00
parent 1b152f4482
commit cc7533e152
5 changed files with 35 additions and 20 deletions

8
10.py
View File

@ -1,5 +1,6 @@
import os
class game():
def __init__(self):
self.secret_word = input('Skriv inn det hemmelige ordet: ')
@ -8,10 +9,12 @@ class game():
os.system('clear')
def getWord(self):
return ''.join([('*' if (ch in self.lettersLeft) else ch) for ch in list(self.secret_word)])
return ''.join([('*' if (ch in self.lettersLeft) else ch)
for ch in list(self.secret_word)])
def removeLetterFromLettersLeft(self, letter):
self.lettersLeft = list(filter(lambda leftLetter: leftLetter != letter, self.lettersLeft))
self.lettersLeft = list(
filter(lambda leftLetter: leftLetter != letter, self.lettersLeft))
def gameOver(self):
print('Du har ingen liv igjen.')
@ -48,6 +51,7 @@ class game():
self.update()
input("Trykk enter for å fortsette...")
if __name__ == "__main__":
myGame = game()
myGame.loop()

View File

@ -1,4 +1,3 @@
def numberPyramid(length):
for i in range(length):
row = ''
@ -6,6 +5,7 @@ def numberPyramid(length):
row += f'{k+1} '
print(row)
def numberPyramidGenerator():
currentList = ['1']
while True:
@ -16,11 +16,13 @@ def numberPyramidGenerator():
def solutionWithForLoops(n):
return numberPyramid(n)
def solutionWithGenerator(n):
myGenerator = numberPyramidGenerator()
for i in range(n):
print(next(myGenerator))
if __name__ == "__main__":
n = int(input('n: '))
print(solutionWithForLoops(n))

View File

@ -7,6 +7,7 @@ def fibonacciIterative(n):
k1 = previousK2
return k1
fibonacciSum = lambda n: sum([fibonacciIterative(i) for i in range(1, n + 1)])
fibonacciList = lambda n: [fibonacciIterative(i) for i in range(1, n + 1)]

View File

@ -1,9 +1,13 @@
def alternateSum(n):
positiveNumbers = [num**2 for num in [i for i in range(1,n+1) if i % 2 != 0]]
negativeNumbers = [-num**2 for num in [i for i in range(1,n+1) if i % 2 == 0]]
positiveNumbers = [
num**2 for num in [i for i in range(1, n + 1) if i % 2 != 0]
]
negativeNumbers = [
-num**2 for num in [i for i in range(1, n + 1) if i % 2 == 0]
]
return sum(positiveNumbers + negativeNumbers)
if __name__ == "__main__":
n = int(input('n: '))
print(alternateSum(n))

View File

@ -7,6 +7,7 @@ def AlternateNumberGenerator():
n = n + (-counter**2 if isEven(counter) else counter**2)
counter += 1
def alternateSumStopAt(k):
numGen = AlternateNumberGenerator()
previousN = None
@ -17,7 +18,10 @@ def alternateSumStopAt(k):
n = next(numGen)
iterations += 1
print(f'Summen av tallene før summen blir større enn k er {previousN}. Antall iterasjoner: {iterations}')
print(
f'Summen av tallene før summen blir større enn k er {previousN}. Antall iterasjoner: {iterations}'
)
if __name__ == "__main__":
k = int(input('k: '))