Search Header Logo
String.format()

String.format()

Assessment

Presentation

Computers

9th - 10th Grade

Easy

Created by

Calum Gordon

Used 2+ times

FREE Resource

17 Slides • 21 Questions

1

String.format()

Formatting printed output to meet user requirements

media

2

media

3

media

4

Multiple Select

Question image

In this lesson I am going to learn to ... ?

1

Format printed output to meet specific requirements

2

Format printed output suitable for the user

3

Save output to text files

4

Input data from text files

5

media

6

Multiple Choice

Which code will loop through all items in the data structure?

wizards = ["Gandalf", "Saruman", "Sauron", "Radagast"]

1

for wizard in wizards:

print(wizard)

2

for wizards in wizard:

print(wizard)

3

while wizard in wizards:

print(wizard)

4

for wizard in range(len(wizards)):

print(wizard)

7

media

8

Multiple Choice

Question image

Output from this program will be .... ?

1

Cheese = 4

Ham = 4

Tuna = 3

2

Cheese = 3

Ham = 4

Tuna = 4

3

Cheese = 4

Tuna = 3

Ham = 4

4

Cheese=4

Ham=4

Tuna=3

9

media

10

Multiple Select

Question image

Choose two reasons for this program output being NOT user-friendly ...

1

No titles on the output

2

Number values are not aligned

3

Too few items

4

Not in alphabetical order

11

media

12

Multiple Select

The maximum width of program output is 80 characters and each column must be of an equal size.

Which of these options represent valid numbers of columns in the output?

1

4

2

5

3

3

4

6

13

Fill in the Blanks

Type answer...

14

media

15

Fill in the Blanks

Type answer...

16

media

17

Multiple Choice

What output would this produce?

print("Gandalf has {} personas.".format(2))

1

Gandalf has 2 personas

2

Gandalf has personas

3

Gandalf has personas Gandalf has personas

4

Gandalf has two personas

18

Multiple Choice

What output would this produce?

print("{}, {} and {}.".format("red", "green", "blue"))

1

red, green and blue

2

blue, green and red

3

red, green, blue

4

red, red and blue

19

media

20

Multiple Choice

What output would this produce?

print("I like to eat {1}, {2} and {0}".format("fish","chips","peas"))

1

I like to eat chips, peas and fish

2

I like to eat fish, chips and peas

3

I like to eat peas, chips and fish

4

I like to eat chips, fish and peas

21

Multiple Choice

What output would this produce?

a = 8

b = 5

c = "apples"

d = "bananas"

print("Gandalf ate {1} {0}",format(d,a))

1

Gandalf ate 8 bananas

2

Gandalf ate 8 apples

3

Gandalf ate 5 apples

4

Gandalf ate bananas 8

22

media

23

Fill in the Blanks

Type answer...

24

media

25

Multiple Choice

Question image

Which field widths would produce columnar output as shown?

1

{:8}{:7}{:5}

2

{:7}{:6}{:5}

3

{:7}{:7}{:7}

4

{:6}{:5}{:5}

26

media

27

Multiple Choice

Choose the field that is right-aligned ...

1

{:>10}

2

{:<10}

3

{:^10}

4

{:.10f}

28

Multiple Choice

Choose the field that is centre-aligned ...

1

{:>6}

2

{:<6}

3

{:^6}

4

{:.6f}

29

media

30

Multiple Choice

Predict the output of this code:

print("{0:<10}{2:^8}{1:>4}".format("Wizard","Colour","Age"))

print("{0:<10}{2:^8}{1:>4}".format("Gandalf","Grey","999"))

print("{0:<10}{2:^8}{1:>4}".format("Sauron","Black","2500"))

print("{0:<10}{2:^8}{1:>4}".format("Saruman","White","1199"))

1
2
3
4

31

media

32

Fill in the Blanks

Type answer...

33

media

34

Multiple Select

Question image

Choose all the ways in which the output has been improved ...

1

Arranged in columns

2

Alignment applied

3

Text dividers used

4

Field headings used

35

media

36

Multiple Select

Question image

In this lesson I have learned to ...

1

Format printed output using <string>.format()

2

Use placeholders {}

3

Use alignment

4

Arrange output in columns

37

Open Ended

Question image

Thinking Hard

What have you learnt today?

What can you do with this knowledge/skill/understanding?

What do you still need to know?

(press Shift+Enter to take a new line ...)

38

Poll

Question image

How much of this lesson have you understood?

None of it

Some of it

Most of it

All of it

String.format()

Formatting printed output to meet user requirements

media

Show answer

Auto Play

Slide 1 / 38

SLIDE