Add inspera test files
This commit is contained in:
parent
e88553337e
commit
4ac06af2c6
21
Exercise 4 - Inspera/10.py
Normal file
21
Exercise 4 - Inspera/10.py
Normal 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])
|
32
Exercise 4 - Inspera/11.py
Normal file
32
Exercise 4 - Inspera/11.py
Normal 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)
|
4
Exercise 4 - Inspera/12.py
Normal file
4
Exercise 4 - Inspera/12.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
def correct_word(string):
|
||||||
|
return bool(re.match('^\w+$', string))
|
8
Exercise 4 - Inspera/13.py
Normal file
8
Exercise 4 - Inspera/13.py
Normal 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
|
5
Exercise 4 - Inspera/15.py
Normal file
5
Exercise 4 - Inspera/15.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
def spam_with_questions(question) -> str:
|
||||||
|
while True:
|
||||||
|
answer = input(question).lower()
|
||||||
|
if answer == 'stopp':
|
||||||
|
break
|
12
Exercise 4 - Inspera/16.py
Normal file
12
Exercise 4 - Inspera/16.py
Normal 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')
|
3
Exercise 4 - Inspera/17.py
Normal file
3
Exercise 4 - Inspera/17.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
def triangle(h):
|
||||||
|
for n in range(1,h+1):
|
||||||
|
print('* '*n)
|
3
Exercise 4 - Inspera/18.py
Normal file
3
Exercise 4 - Inspera/18.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
def triangle(h):
|
||||||
|
for n in reversed(range(1,h+1)):
|
||||||
|
print('* '*n)
|
4
Exercise 4 - Inspera/19.py
Normal file
4
Exercise 4 - Inspera/19.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
def isosceles_triangle(h):
|
||||||
|
for i in range(1, h+1):
|
||||||
|
spaces = h-i
|
||||||
|
print(spaces*' ' + i*'* ')
|
13
Exercise 4 - Inspera/20.py
Normal file
13
Exercise 4 - Inspera/20.py
Normal 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}')
|
4
Exercise 4 - Inspera/5.py
Normal file
4
Exercise 4 - Inspera/5.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
x = 3
|
||||||
|
while x:
|
||||||
|
print('#'*x)
|
||||||
|
x-=1
|
1
Exercise 4 - Inspera/7.py
Normal file
1
Exercise 4 - Inspera/7.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
print(f'Det minste talled du skrev inn var { min([int(input("Skriv et tall: ")) for _ in range(5)]) }.')
|
3
Exercise 4 - Inspera/9.py
Normal file
3
Exercise 4 - Inspera/9.py
Normal 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)]))
|
Loading…
Reference in New Issue
Block a user