Spørsmål fra tidligere eksamener Flashcards

1
Q

Hva skrives ut med følgende kommando?:

print(“The problem is not the problem”[4:11])

A

problem

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Hva skrives ut med følgende kommando?:

print(“The problem is you attitude about the problem”.split())

A

[‘The’, ‘problem’, ‘is’, ‘you’, ‘attitude’, ‘about’, ‘the’, ‘problem’]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Hva skrives ut med følgende kommando?:

print(“Do or do not”.find(“do”))

A

6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Hva skrives ut med følgende kommando?:

print(“There is no try”.upper())

A

THERE IS NO TRY

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Hva skrives ut med følgende kommando?:

print(“My favourite courses: {2}, {0}, {3}, {1}”.format(“fys230”, “inf120”, “math112”, “stat100”))

A

My favourite courses: math112, fys230, stat100, inf120

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Hva skrives ut med følgende kommando?:

print(“Cartoon”.replace(“o”, “a”))

A

Cartaan

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Hva skrives ut med følgende kommando?:

print(int(10.0/int(“2”)))

A

5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Hva skrives ut med følgende kommando?:

print(“*“.join([“student”, “at”, “NMBU”.lower()]))

A

studentatnmbu

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Hva skrives ut med følgende kommando?:

print(“The person is {0:.2f} m tall, weighs {2} kg and has shoe size {1}.”.format(1.5999, 40, 45))

A

The person is 1.60 m tall, weighs 45 kg and has shoe size 40.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Hva skrives ut med følgende kommando?:

print(27 == 42)

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Hva skrives ut med følgende kommando?:

print(“Pizza with ham and cheese.”.replace(“ham”, “pepperoni”))

A

Pizza with pepperoni and cheese.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Hva skrives ut med følgende kommando?:

print(“The best mirror is an old friend.”.split()[-3:-1])

A

[‘an’, ‘old’]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Hva skrives ut med følgende kommando?:

print(“house”.upper() in “The house is on fire”)

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Hva skrives ut med følgende kommando?:

print(“Always remember: it is never too late”.split(“:”)[0].split()[0][0:-3])

A

Alw

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Hva vil denne listen inneholde om den printes?:

[e + f for e, f in [[4, 2], [4, 3]]]

A

[6, 7]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Hva vil denne listen inneholde om den printes?:

[sum([n, m, o]) for n, m, o in zip([2, 1, 4], [0, 3, 4], [0, 6, 2])]

A

[2, 10, 10]

17
Q

Hva vil denne listen inneholde om den printes?:

[name[-2:] for name in [“Ida”, “Olav”, “Kristin”] if “a” not in name]

A

[‘in’]

18
Q

Hva vil denne listen inneholde om den printes?:

[z + z * z for z in range (1, 6, 2)]

A

[2, 12, 30]

19
Q

Hva skrives ut med følgende kommando?:

print(“A list of cities: {2}, {1}, {3}, {0}”.format(“Quito”, “Rio”, “Oslo”, “Perth”))

A

A list of cities: Oslo, Rio, Perth, Quito

20
Q

Hva skrives ut med følgende kommando?:

print(“They call it a Royale with cheese.”[-7:-1])

A

cheese

21
Q

Hva skrives ut med følgende kommando?:

print(“John” in “John is a great bloke.”)

A

True

22
Q

Hva skrives ut med følgende kommando?:

print(“Ice Cream”.upper())

A

ICE CREAM

23
Q

Gitt følgende data:

price1 = 3425.234
price2 = -56837.32

Hva skrives ut med følgende kommando?:

print(f”Price one is ${price1:.2f}”)

A

Price one is $3425.23

24
Q

Gitt følgende data:

price1 = 3425.234
price2 = -56837.32

Hva skrives ut med følgende kommando?:

print(f”Price one is ${price1:10}”)

A

Price one is $ 3425.234

Her brukes tilsammen 10 plasser på å skrive tallet etter $ tegnet.

25
Q

Gitt følgende data:

price1 = 3425.234
price2 = -56837.32

Hva skrives ut med følgende kommando?:

print(f”Price one is ${price1:010}”)

A

Price one is $003425.234

26
Q

Gitt følgende data:

price1 = 3425.234
price2 = -56837.32

Hva skrives ut med følgende kommando?:

print(f”Price one is ${price1:<010}”)

A

Price one is $3425.23400

27
Q

Gitt følgende data:

price1 = 3425.234
price2 = -56837.32

Hva skrives ut med følgende kommando?:

print(f”Price one is ${price1:>010}”)

A

Price one is $003425.234

28
Q

Gitt følgende data:

price1 = 3425.234
price2 = -56837.32

Hva skrives ut med følgende kommando?:

print(f”price two is ${price2:^10}”)
print(f”Price one is ${price1:^10}”)

A

price two is $-56837.32
Price one is $ 3425.234

Sentrerer begge tallene om 10 karakterer

29
Q

Gitt følgende data:

price1 = 3425.234
price2 = -56837.32

Hva skrives ut med følgende kommando?:

print(f”Price one is ${price1:+}”)
print(f”Price two is ${price2:+}”)

A

Price one is $+3425.234
Price two is $-56837.32

30
Q

Gitt følgende data:

price1 = 30000000000.234

Hva skrives ut med følgende kommando?:

print(f”Price one is ${price1:,}”)

A

Price one is $30,000,000,000.234

31
Q

Gitt følgende data:

price1 = 3425.234
price2 = -56837.32

Hva skrives ut med følgende kommando?:

print(f”Price one is ${price1:+,.2f}”)

A

Price one is $+3,425.23

32
Q

Gitt følgende data:

price1 = 123456.789

Hva skrives ut med følgende kommando?:

print(f”Price one is ${price1:e}”)

A

Price one is $1.234568e+05

33
Q

Gitt følgende data og kommando, hva vil printes og hva betyr det?

a = 27
b = 5
x = divmod(a, b)
print(x)

A

(5, 2) vil printes.

Funksjonen Divmod brukes for å sjekke hvor mange ganger et tall kan deles på et annet tall.

27 kan deles 5 ganger på 5, og 2 vil være resten.

34
Q

Gitt følgende program, hva vil printes?:

a = 42
b = 5
x = divmod(a, b)
print(x)

A

(8, 3)

35
Q

Hvordan kan vi kontrollere om et tall er et partall?

Eksempelvis med a = 8

A

a % 2 == 0
Out[40]: True

Output vil være True dersom det er et partall, og False om det er et oddetall.

*Dette skrives direkte inn i konsollen

36
Q

Hvordan kan vi regne ut kvadratroten av et tall i Python?

A

Ved å importere math biblioteket, og deretter bruke sqrt funksjonen.

Eksempel:

import math

a = 9
r = math.sqrt(a)
print(r)

37
Q
A