

String.format()
Presentation
•
Computers
•
9th - 10th Grade
•
Easy
Calum Gordon
Used 2+ times
FREE Resource
17 Slides • 21 Questions
1
String.format()
Formatting printed output to meet user requirements

2
3
4
Multiple Select
In this lesson I am going to learn to ... ?
Format printed output to meet specific requirements
Format printed output suitable for the user
Save output to text files
Input data from text files
5
6
Multiple Choice
Which code will loop through all items in the data structure?
wizards = ["Gandalf", "Saruman", "Sauron", "Radagast"]
for wizard in wizards:
print(wizard)
for wizards in wizard:
print(wizard)
while wizard in wizards:
print(wizard)
for wizard in range(len(wizards)):
print(wizard)
7
8
Multiple Choice
Output from this program will be .... ?
Cheese = 4
Ham = 4
Tuna = 3
Cheese = 3
Ham = 4
Tuna = 4
Cheese = 4
Tuna = 3
Ham = 4
Cheese=4
Ham=4
Tuna=3
9
10
Multiple Select
Choose two reasons for this program output being NOT user-friendly ...
No titles on the output
Number values are not aligned
Too few items
Not in alphabetical order
11
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?
4
5
3
6
13
Fill in the Blanks
Type answer...
14
15
Fill in the Blanks
Type answer...
16
17
Multiple Choice
What output would this produce?
print("Gandalf has {} personas.".format(2))
Gandalf has 2 personas
Gandalf has personas
Gandalf has personas Gandalf has personas
Gandalf has two personas
18
Multiple Choice
What output would this produce?
print("{}, {} and {}.".format("red", "green", "blue"))
red, green and blue
blue, green and red
red, green, blue
red, red and blue
19
20
Multiple Choice
What output would this produce?
print("I like to eat {1}, {2} and {0}".format("fish","chips","peas"))
I like to eat chips, peas and fish
I like to eat fish, chips and peas
I like to eat peas, chips and fish
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))
Gandalf ate 8 bananas
Gandalf ate 8 apples
Gandalf ate 5 apples
Gandalf ate bananas 8
22
23
Fill in the Blanks
Type answer...
24
25
Multiple Choice
Which field widths would produce columnar output as shown?
{:8}{:7}{:5}
{:7}{:6}{:5}
{:7}{:7}{:7}
{:6}{:5}{:5}
26
27
Multiple Choice
Choose the field that is right-aligned ...
{:>10}
{:<10}
{:^10}
{:.10f}
28
Multiple Choice
Choose the field that is centre-aligned ...
{:>6}
{:<6}
{:^6}
{:.6f}
29
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"))
31
32
Fill in the Blanks
Type answer...
33
34
Multiple Select
Choose all the ways in which the output has been improved ...
Arranged in columns
Alignment applied
Text dividers used
Field headings used
35
36
Multiple Select
In this lesson I have learned to ...
Format printed output using <string>.format()
Use placeholders {}
Use alignment
Arrange output in columns
37
Open Ended
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
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

Show answer
Auto Play
Slide 1 / 38
SLIDE
Similar Resources on Wayground
36 questions
Unit 4 T1 Input and output devices
Presentation
•
10th Grade
36 questions
Transformations of Graphs of Linear Functions
Presentation
•
8th - 9th Grade
37 questions
Algoritma Dan Pemograman
Presentation
•
10th Grade
33 questions
[AP GOPO] Unit 1 Review
Presentation
•
10th Grade
32 questions
Adapter Cards
Presentation
•
9th Grade
36 questions
If, Elif, Else, Readability
Presentation
•
9th - 10th Grade
33 questions
Pemrograman Dasar
Presentation
•
10th Grade
32 questions
Robotics AI
Presentation
•
10th Grade
Popular Resources on Wayground
10 questions
HCS SCI 03 Summer School Review 4
Quiz
•
3rd Grade
11 questions
HSMS - Standard Response Protocol
Quiz
•
6th - 8th Grade
16 questions
1.1-1.2 Quiz Review
Quiz
•
9th - 12th Grade
12 questions
Exponent Expressions
Quiz
•
6th Grade
20 questions
Adding and Subtracting Integers
Quiz
•
6th - 7th Grade
11 questions
Northeast States
Quiz
•
3rd - 4th Grade
10 questions
Characterization
Quiz
•
3rd - 7th Grade
10 questions
Common Denominators
Quiz
•
5th Grade