Format
This commit is contained in:
parent
1b152f4482
commit
cc7533e152
8
10.py
8
10.py
@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
class game():
|
class game():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.secret_word = input('Skriv inn det hemmelige ordet: ')
|
self.secret_word = input('Skriv inn det hemmelige ordet: ')
|
||||||
@ -8,10 +9,12 @@ class game():
|
|||||||
os.system('clear')
|
os.system('clear')
|
||||||
|
|
||||||
def getWord(self):
|
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):
|
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):
|
def gameOver(self):
|
||||||
print('Du har ingen liv igjen.')
|
print('Du har ingen liv igjen.')
|
||||||
@ -48,6 +51,7 @@ class game():
|
|||||||
self.update()
|
self.update()
|
||||||
input("Trykk enter for å fortsette...")
|
input("Trykk enter for å fortsette...")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
myGame = game()
|
myGame = game()
|
||||||
myGame.loop()
|
myGame.loop()
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
def numberPyramid(length):
|
def numberPyramid(length):
|
||||||
for i in range(length):
|
for i in range(length):
|
||||||
row = ''
|
row = ''
|
||||||
@ -6,6 +5,7 @@ def numberPyramid(length):
|
|||||||
row += f'{k+1} '
|
row += f'{k+1} '
|
||||||
print(row)
|
print(row)
|
||||||
|
|
||||||
|
|
||||||
def numberPyramidGenerator():
|
def numberPyramidGenerator():
|
||||||
currentList = ['1']
|
currentList = ['1']
|
||||||
while True:
|
while True:
|
||||||
@ -16,11 +16,13 @@ def numberPyramidGenerator():
|
|||||||
def solutionWithForLoops(n):
|
def solutionWithForLoops(n):
|
||||||
return numberPyramid(n)
|
return numberPyramid(n)
|
||||||
|
|
||||||
|
|
||||||
def solutionWithGenerator(n):
|
def solutionWithGenerator(n):
|
||||||
myGenerator = numberPyramidGenerator()
|
myGenerator = numberPyramidGenerator()
|
||||||
for i in range(n):
|
for i in range(n):
|
||||||
print(next(myGenerator))
|
print(next(myGenerator))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
n = int(input('n: '))
|
n = int(input('n: '))
|
||||||
print(solutionWithForLoops(n))
|
print(solutionWithForLoops(n))
|
@ -7,6 +7,7 @@ def fibonacciIterative(n):
|
|||||||
k1 = previousK2
|
k1 = previousK2
|
||||||
return k1
|
return k1
|
||||||
|
|
||||||
|
|
||||||
fibonacciSum = lambda n: sum([fibonacciIterative(i) for i in range(1, n + 1)])
|
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)]
|
fibonacciList = lambda n: [fibonacciIterative(i) for i in range(1, n + 1)]
|
||||||
|
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
|
|
||||||
def alternateSum(n):
|
def alternateSum(n):
|
||||||
positiveNumbers = [num**2 for num in [i for i in range(1,n+1) if i % 2 != 0]]
|
positiveNumbers = [
|
||||||
negativeNumbers = [-num**2 for num in [i for i in range(1,n+1) if i % 2 == 0]]
|
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)
|
return sum(positiveNumbers + negativeNumbers)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
n = int(input('n: '))
|
n = int(input('n: '))
|
||||||
print(alternateSum(n))
|
print(alternateSum(n))
|
@ -7,6 +7,7 @@ def AlternateNumberGenerator():
|
|||||||
n = n + (-counter**2 if isEven(counter) else counter**2)
|
n = n + (-counter**2 if isEven(counter) else counter**2)
|
||||||
counter += 1
|
counter += 1
|
||||||
|
|
||||||
|
|
||||||
def alternateSumStopAt(k):
|
def alternateSumStopAt(k):
|
||||||
numGen = AlternateNumberGenerator()
|
numGen = AlternateNumberGenerator()
|
||||||
previousN = None
|
previousN = None
|
||||||
@ -17,7 +18,10 @@ def alternateSumStopAt(k):
|
|||||||
n = next(numGen)
|
n = next(numGen)
|
||||||
iterations += 1
|
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__":
|
if __name__ == "__main__":
|
||||||
k = int(input('k: '))
|
k = int(input('k: '))
|
||||||
|
Loading…
Reference in New Issue
Block a user