Add inspera test files

This commit is contained in:
Oystein Kristoffer Tveit 2020-10-01 12:05:45 +02:00
parent e88553337e
commit 4ac06af2c6
13 changed files with 113 additions and 0 deletions

View File

@ -0,0 +1,21 @@
month = input('Skriv inn en måned: ').lower()
if month == 'februar':
year = input('Skriv inn et år: ')
isLeapyear = int(year) % 4 == 0
print(29 if isLeapyear else 28)
else:
months = {
"januar": 31,
# "februar": 30,
"mars": 31,
"april": 30,
"mai": 31,
"juni": 30,
"july": 31, # Hmmm
"august": 31,
"september": 30,
"oktober": 31,
"november": 30,
"desember": 31
}
print(months[month])

View File

@ -0,0 +1,32 @@
months = {
"januar": 31,
# "februar": 30,
"mars": 31,
"april": 30,
"mai": 31,
"juni": 30,
"july": 31, # Hmmm
"august": 31,
"september": 30,
"oktober": 31,
"november": 30,
"desember": 31
}
def myMonth():
while True:
try:
month = input('Skriv inn en måned: ').lower()
if month == 'februar':
year = int(input('Skriv inn et år: '))
assert ((year >= 0) and ( year <= 2020))
isLeapyear = year % 4 == 0
days = 29 if isLeapyear else 28
else:
assert month in months
days = month[month]
return f'Det er {days} dager i denne måneden'
except:
print('Ugyldig input! Prøv på nytt!')
print(myMonth)

View File

@ -0,0 +1,4 @@
import re
def correct_word(string):
return bool(re.match('^\w+$', string))

View File

@ -0,0 +1,8 @@
import re
def count_letters(string):
try:
assert bool(re.match('^\w+$', string))
return len(string)
except AssertionError:
return -1

View File

@ -0,0 +1,5 @@
def spam_with_questions(question) -> str:
while True:
answer = input(question).lower()
if answer == 'stopp':
break

View File

@ -0,0 +1,12 @@
def energy_efficient_spamming(q1, q2):
try:
assert len(q1)>len(q2)
answer = input(q1)
while True:
if answer == 'stopp':
break
answer = input(q2)
except AssertionError:
return
energy_efficient_spamming('jadu', 'nei')

View File

@ -0,0 +1,3 @@
def triangle(h):
for n in range(1,h+1):
print('* '*n)

View File

@ -0,0 +1,3 @@
def triangle(h):
for n in reversed(range(1,h+1)):
print('* '*n)

View File

@ -0,0 +1,4 @@
def isosceles_triangle(h):
for i in range(1, h+1):
spaces = h-i
print(spaces*' ' + i*'* ')

View File

@ -0,0 +1,13 @@
def cubeInput():
while True:
try:
l,w,h = (float(input('Lengde: ')), float(input('Bredde: ')), float(input('Høyde: ')))
assert w != l and l != h and w != h
return (l,w,h)
except AssertionError:
print('Morten er ikke fornøyd, prøv igjen')
except ValueError:
print('Det er ikke et tall, prøv igjen')
d = min(cubeInput())
print(f'Den største kuben vil ha et volum på {d**3}')

View File

@ -0,0 +1,4 @@
x = 3
while x:
print('#'*x)
x-=1

View File

@ -0,0 +1 @@
print(f'Det minste talled du skrev inn var { min([int(input("Skriv et tall: ")) for _ in range(5)]) }.')

View File

@ -0,0 +1,3 @@
def print_table(n):
for a in range(1, n+1):
print(' '.join([str(a*b) for b in range(1, n+1)]))