1
00:00:00,240 --> 00:00:02,546
Hey guys, welcome to this lesson on

2
00:00:02,546 --> 00:00:06,682
how the input() function works in Auditorium.

3
00:00:06,682 --> 00:00:08,970
Now, this is an important lesson

4
00:00:08,970 --> 00:00:11,831
because inputs actually work a little bit differently in

5
00:00:11,831 --> 00:00:16,445
Auditorium compared to what you have seen so far elsewhere.

6
00:00:16,445 --> 00:00:19,857
Now the first thing you'll notice is that in exercises

7
00:00:19,857 --> 00:00:22,108
that require an input,

8
00:00:22,108 --> 00:00:25,647
the Input pane will show up on the bottom left.

9
00:00:25,647 --> 00:00:28,680
And here occasionally I might start you off

10
00:00:28,680 --> 00:00:30,229
with some example inputs,

11
00:00:30,229 --> 00:00:33,030
but if you see the Input pane, you can always delete

12
00:00:33,030 --> 00:00:36,090
what I've written in there and replace it with your own,

13
00:00:36,090 --> 00:00:38,247
or write multiple lines of inputs,

14
00:00:38,247 --> 00:00:41,683
but how does it work exactly in Auditorium?

15
00:00:41,683 --> 00:00:46,530
Well, it's mostly used for us to be able to test your code,

16
00:00:46,530 --> 00:00:48,862
to be able to see that you are writing the correct code

17
00:00:48,862 --> 00:00:51,630
and to make sure that you are on the right track.

18
00:00:51,630 --> 00:00:53,130
So let's take a look at

19
00:00:53,130 --> 00:00:55,198
how inputs work in a little bit more detail.

20
00:00:55,198 --> 00:00:59,325
Take a look at the code that I've written here, print,

21
00:00:59,325 --> 00:01:01,937
and then the input function,

22
00:01:01,937 --> 00:01:04,061
and then closing the print statement.

23
00:01:04,061 --> 00:01:05,647
Go ahead and run this code

24
00:01:05,647 --> 00:01:09,076
and see what gets printed in the Output area.

25
00:01:09,076 --> 00:01:12,543
Can you see where it comes from in the Input pane?

26
00:01:14,580 --> 00:01:18,002
Now notice how I've added two more of these lines of code.

27
00:01:18,002 --> 00:01:19,749
Now, if you go ahead

28
00:01:19,749 --> 00:01:22,435
and run this code now as it is,

29
00:01:22,435 --> 00:01:25,921
you should see all three names in the Input area printed

30
00:01:25,921 --> 00:01:27,549
into the Output area.

31
00:01:27,549 --> 00:01:30,784
So the way that input() functions work in Auditorium is

32
00:01:30,784 --> 00:01:34,320
that you can go line by line from top

33
00:01:34,320 --> 00:01:36,660
to bottom in the Input area,

34
00:01:36,660 --> 00:01:39,000
and as long as you write the input function,

35
00:01:39,000 --> 00:01:41,121
so the word, "input" plus the opening

36
00:01:41,121 --> 00:01:44,464
and closing parentheses, it will look in the Input area

37
00:01:44,464 --> 00:01:48,319
and pick out each one line by line.

38
00:01:48,319 --> 00:01:50,525
But now we have an interesting problem,

39
00:01:50,525 --> 00:01:54,210
what if I have four of these lines of code to try

40
00:01:54,210 --> 00:01:55,889
and pull in four inputs?

41
00:01:55,889 --> 00:01:58,530
While, if you take a look in the Input area,

42
00:01:58,530 --> 00:02:01,500
there are clearly only three lines of inputs.

43
00:02:01,500 --> 00:02:05,280
Jane, Ben, and Tom, there is no fourth input line.

44
00:02:05,280 --> 00:02:06,411
So what happens here?

45
00:02:06,411 --> 00:02:08,204
Well, if you go ahead and run this code,

46
00:02:08,204 --> 00:02:10,058
you will see an error.

47
00:02:10,058 --> 00:02:13,046
And this is where you are trying to pull in an input

48
00:02:13,046 --> 00:02:15,623
that doesn't exist in the Input pane.

49
00:02:15,623 --> 00:02:18,346
So if you familiarize yourself with these errors,

50
00:02:18,346 --> 00:02:20,494
then if it does happen in the future,

51
00:02:20,494 --> 00:02:23,065
you'll know exactly what's going on.

52
00:02:23,065 --> 00:02:26,873
So when you do see that end of line, then you'll know that,

53
00:02:26,873 --> 00:02:29,147
"Oh, maybe I've added one too many inputs,

54
00:02:29,147 --> 00:02:32,947
and it doesn't actually exist in the Input pane."

55
00:02:32,947 --> 00:02:34,890
Now the final thing I want

56
00:02:34,890 --> 00:02:38,910
to mention is unlike previously when you've been writing

57
00:02:38,910 --> 00:02:42,759
Python for your projects, when you use the input prompt,

58
00:02:42,759 --> 00:02:45,900
because we don't need the prompt in order to get hold

59
00:02:45,900 --> 00:02:49,476
of the input, this prompt actually goes into the output next

60
00:02:49,476 --> 00:02:52,145
to the input name.

61
00:02:52,145 --> 00:02:55,574
So when you run the code here, as you see right now,

62
00:02:55,574 --> 00:02:59,460
you'll see the words, "What is your name?"

63
00:02:59,460 --> 00:03:01,902
And then immediately the first line of the input.

64
00:03:01,902 --> 00:03:04,500
Now this is not what we want

65
00:03:04,500 --> 00:03:07,138
to do on the Auditorium coding exercises

66
00:03:07,138 --> 00:03:10,440
because we're testing your outputs to make sure

67
00:03:10,440 --> 00:03:13,512
that you're getting the right results from your code.

68
00:03:13,512 --> 00:03:18,512
So in all cases, when you are using the input() in Auditorium,

69
00:03:19,020 --> 00:03:22,564
I recommend to use it without any prompt text.

70
00:03:22,564 --> 00:03:26,730
So simply the keyword input, an open parentheses

71
00:03:26,730 --> 00:03:28,320
and a closing parentheses,

72
00:03:28,320 --> 00:03:30,806
and that entire block will be replaced

73
00:03:30,806 --> 00:03:34,953
by whichever Input you have in the input pane.

74
00:03:34,953 --> 00:03:38,820
Now take a look at this Demo coding exercise.

75
00:03:38,820 --> 00:03:43,350
Now without changing any of the code in main.py,

76
00:03:43,350 --> 00:03:46,227
go ahead and simply click on the SUBMIT button

77
00:03:46,227 --> 00:03:50,833
and run all of the tests that we've prepared for this exercise.

78
00:03:50,833 --> 00:03:53,028
Now, one thing you'll notice is

79
00:03:53,028 --> 00:03:55,584
that the code should pass all

80
00:03:55,584 --> 00:03:59,030
of the tests in the Evaluation pane.

81
00:03:59,030 --> 00:04:04,030
But notice in the Input area, you only see two numbers.

82
00:04:04,070 --> 00:04:08,112
So the code here on Line 4 multiplies num1,

83
00:04:08,112 --> 00:04:10,561
which comes from the first line of the Input area,

84
00:04:10,561 --> 00:04:13,824
by num2, which comes from the second line

85
00:04:13,824 --> 00:04:15,298
of the Input area.

86
00:04:15,298 --> 00:04:18,463
Now, in order for us to be able to test your code

87
00:04:18,463 --> 00:04:20,950
to make sure that you're doing the right things,

88
00:04:20,950 --> 00:04:25,166
we will add hidden inputs and hidden tests.

89
00:04:25,166 --> 00:04:26,894
So when you run the code,

90
00:04:26,894 --> 00:04:31,322
you will see other tests being run in addition to the input

91
00:04:31,322 --> 00:04:33,294
of 2*3.

92
00:04:33,294 --> 00:04:37,519
This way we can ensure that your code is actually code

93
00:04:37,519 --> 00:04:39,840
and it's doing what it's supposed to do,

94
00:04:39,840 --> 00:04:42,464
and it covers all of the corner and edge cases.

95
00:04:42,464 --> 00:04:47,464
Now notice what happens if a student completes the exercise

96
00:04:48,210 --> 00:04:50,841
without actually completing the objectives of

97
00:04:50,841 --> 00:04:52,745
what we're testing them on.

98
00:04:52,745 --> 00:04:56,520
So in this case, we're pulling-in num1 from Line 1

99
00:04:56,520 --> 00:04:57,851
of our Input, which is 2,

100
00:04:57,851 --> 00:05:01,980
and we're pulling-in num2, which is 3,

101
00:05:01,980 --> 00:05:05,940
and then we simply printed 6 on Line 4,

102
00:05:05,940 --> 00:05:09,670
'cause I know very easily that 2*3 is 6.

103
00:05:09,670 --> 00:05:11,602
Now, however, if you go ahead

104
00:05:11,602 --> 00:05:15,450
and click on the SUBMIT button without, again, changing any

105
00:05:15,450 --> 00:05:17,798
of the code in the Demo, then you'll see that one

106
00:05:17,798 --> 00:05:21,569
of the test pass, but the other one fails.

107
00:05:21,569 --> 00:05:23,152
And this is because

108
00:05:23,152 --> 00:05:26,753
that the first test case is 2*3,

109
00:05:26,753 --> 00:05:28,807
which does equal 6,

110
00:05:28,807 --> 00:05:32,558
so your output from your code is 6,

111
00:05:32,558 --> 00:05:34,880
and the expected output is also 6.

112
00:05:34,880 --> 00:05:36,897
So that works just fine.

113
00:05:36,897 --> 00:05:41,230
Now, however, in the second test case, this doesn't pass

114
00:05:41,230 --> 00:05:44,836
because we're printing the output 6,

115
00:05:44,836 --> 00:05:49,140
whereas we've got some hidden inputs testing your code

116
00:05:49,140 --> 00:05:51,480
against the inputs of 5 and 5.

117
00:05:51,480 --> 00:05:54,849
5*5 is 25, and 6 does not equal 25

118
00:05:54,849 --> 00:05:57,148
and that's why the second test fails.

119
00:05:57,148 --> 00:05:59,713
Now you might think to yourself, well, how can I write code

120
00:05:59,713 --> 00:06:02,577
that works for all of these test cases?

121
00:06:02,577 --> 00:06:06,099
Well, you would have to write actual code like

122
00:06:06,099 --> 00:06:10,147
what you saw in the previous slide, which takes in any input

123
00:06:10,147 --> 00:06:12,540
and doesn't care what number it is,

124
00:06:12,540 --> 00:06:15,766
and simply multiplies the first number by the second number.

125
00:06:15,766 --> 00:06:18,625
So head back over there if you're confused,

126
00:06:18,625 --> 00:06:22,530
and see if you can fix this slide so

127
00:06:22,530 --> 00:06:24,160
that all the test cases pass.

128
00:06:24,160 --> 00:06:27,217
Now, try it yourself, try pulling in some

129
00:06:27,217 --> 00:06:29,702
of the inputs from the Input area.

130
00:06:29,702 --> 00:06:32,869
So look at the Input pane at the bottom left,

131
00:06:32,869 --> 00:06:35,890
go ahead and change the values that are in there,

132
00:06:35,890 --> 00:06:39,057
you can add as many lines of input as you want

133
00:06:39,057 --> 00:06:43,042
and then try writing some code in main.py in order

134
00:06:43,042 --> 00:06:47,477
to print the different lines of input into the Output area.

135
00:06:47,477 --> 00:06:52,020
If you get stuck, look back at the previous slides to see

136
00:06:52,020 --> 00:06:55,649
how you can pull in the input using the input function.

137
00:06:55,649 --> 00:06:59,876
Now in the final coding exercise of this lesson, I want you

138
00:06:59,876 --> 00:07:02,657
to figure out how to pull in the inputs

139
00:07:02,657 --> 00:07:06,773
and calculate the number of letters in the names

140
00:07:06,773 --> 00:07:08,593
that I put into the input.

141
00:07:08,593 --> 00:07:11,850
Now just before we do that, I want to show you

142
00:07:11,850 --> 00:07:14,310
how you can actually get hold of the number

143
00:07:14,310 --> 00:07:18,310
of letters from a piece of string in Python.

144
00:07:18,310 --> 00:07:21,236
So the function in Python is called len(), which stands

145
00:07:21,236 --> 00:07:24,756
for length, and you can use len

146
00:07:24,756 --> 00:07:26,417
and then a set of parentheses,

147
00:07:26,417 --> 00:07:29,505
and then inside the parentheses add some text such as

148
00:07:29,505 --> 00:07:31,455
what you see here on Line 1.

149
00:07:31,455 --> 00:07:34,290
And when you print the result of that,

150
00:07:34,290 --> 00:07:35,937
you will see the number of letters in

151
00:07:35,937 --> 00:07:38,372
that text being calculated.

152
00:07:38,372 --> 00:07:42,380
Go ahead and hit RUN CODE and see this for yourself.

153
00:07:42,380 --> 00:07:43,961
So now you're finally ready

154
00:07:43,961 --> 00:07:48,683
to tackle the final coding exercise of this lesson.

155
00:07:48,683 --> 00:07:52,169
So take a look through the instructions, the hints,

156
00:07:52,169 --> 00:07:56,952
and see what we're expecting you to get as an output.

157
00:07:56,952 --> 00:08:00,360
So the task for today is

158
00:08:00,360 --> 00:08:03,512
to pull in the text from the input area.

159
00:08:03,512 --> 00:08:06,574
There will only be one line of inputs,

160
00:08:06,574 --> 00:08:08,610
and this will be a name.

161
00:08:08,610 --> 00:08:10,650
So you can see in the starting example,

162
00:08:10,650 --> 00:08:12,556
I put my name in there,

163
00:08:12,556 --> 00:08:16,196
and your job is to write some code in main.py in order

164
00:08:16,196 --> 00:08:19,294
to print out the number of letters in the name

165
00:08:19,294 --> 00:08:22,200
that's put in the input.

166
00:08:22,200 --> 00:08:24,330
Now of course, remember what I mentioned

167
00:08:24,330 --> 00:08:26,970
before, when we're testing your code, we're going

168
00:08:26,970 --> 00:08:30,036
to pass your code with inputs

169
00:08:30,036 --> 00:08:32,047
that I have hidden away.

170
00:08:32,047 --> 00:08:35,414
So when you submit the code, when you think you are ready,

171
00:08:35,414 --> 00:08:39,933
you'll see different inputs being passed through main.py

172
00:08:39,933 --> 00:08:43,409
and your code has to work for all of them.

173
00:08:43,409 --> 00:08:44,896
So make sure you're writing code

174
00:08:44,896 --> 00:08:48,443
and you're not just simply calculating it using your head,

175
00:08:48,443 --> 00:08:50,608
and that way you'll be able to pass all

176
00:08:50,608 --> 00:08:53,281
of the tests in the Evaluation pane.

177
00:08:53,281 --> 00:08:54,666
So give this a go

178
00:08:54,666 --> 00:08:58,290
and if you get stuck, there's always the next slide

179
00:08:58,290 --> 00:08:59,832
where I'll go through the code solution,

180
00:08:59,832 --> 00:09:02,704
but also you can head back a few more slides previously

181
00:09:02,704 --> 00:09:06,903
and see if you can figure out the solution yourself.

182
00:09:08,670 --> 00:09:11,084
Now we're going to break down the solution into three

183
00:09:11,084 --> 00:09:12,919
distinct parts,

184
00:09:12,919 --> 00:09:15,833
and the first part is the input() function.

185
00:09:15,833 --> 00:09:19,003
The input() function can bring in the value

186
00:09:19,003 --> 00:09:21,162
that's in the Input pane.

187
00:09:21,162 --> 00:09:24,954
So that's the first part we need to get hold of.

188
00:09:24,954 --> 00:09:29,940
Now that we've gotten hold of the text on the first line

189
00:09:29,940 --> 00:09:33,643
of the Input pane, then we need to put it

190
00:09:33,643 --> 00:09:36,071
inside the len() function.

191
00:09:36,071 --> 00:09:37,616
So as I showed you earlier,

192
00:09:37,616 --> 00:09:40,600
the len() function can take any piece of text

193
00:09:40,600 --> 00:09:43,673
and tell you how many characters

194
00:09:43,673 --> 00:09:47,352
or how many letters are in that piece of text.

195
00:09:47,352 --> 00:09:49,249
So in this case, we're simply inserting

196
00:09:49,249 --> 00:09:53,812
what we got from the Input into the len() function in order

197
00:09:53,812 --> 00:09:56,320
to perform this functionality

198
00:09:56,320 --> 00:10:01,320
and let us know how many letters are in the input text.

199
00:10:01,750 --> 00:10:05,760
Now, of course, when you saw it before you simply saw len,

200
00:10:05,760 --> 00:10:08,777
and then in the parentheses we added in plain text,

201
00:10:08,777 --> 00:10:10,821
but in this case, we're writing our code

202
00:10:10,821 --> 00:10:13,511
to perform things automatically

203
00:10:13,511 --> 00:10:17,910
and it has to work for all of the different inputs, not just

204
00:10:17,910 --> 00:10:19,410
for the word Bertrand.

205
00:10:19,410 --> 00:10:21,208
So in this case, we're taking the input

206
00:10:21,208 --> 00:10:24,242
and putting it inside the len() function so

207
00:10:24,242 --> 00:10:26,645
that it'll work even if we switch out the input

208
00:10:26,645 --> 00:10:28,660
with any other name.

209
00:10:28,660 --> 00:10:31,881
Now, the final part is to put all of

210
00:10:31,881 --> 00:10:34,328
that into the print() statement.

211
00:10:34,328 --> 00:10:37,744
So remember, inputs go into the part

212
00:10:37,744 --> 00:10:39,381
between the parentheses.

213
00:10:39,381 --> 00:10:42,017
So now we have a complete program

214
00:10:42,017 --> 00:10:43,990
where we first take the input,

215
00:10:43,990 --> 00:10:48,932
we put it into the len() function, we calculate the length

216
00:10:48,932 --> 00:10:50,770
of the string in the input,

217
00:10:50,770 --> 00:10:53,266
and then we put that into the print() statement

218
00:10:53,266 --> 00:10:56,164
and we print it out into the Output area.

219
00:10:56,164 --> 00:11:01,164
So each of these functions had a distinct role,

220
00:11:01,447 --> 00:11:06,240
and by putting in them one into the other, we end up

221
00:11:06,240 --> 00:11:07,440
with the result we want.

222
00:11:08,280 --> 00:11:09,420
Now, if you got stuck

223
00:11:09,420 --> 00:11:12,323
or if you had any differences in your code, feel free

224
00:11:12,323 --> 00:11:15,270
to go back to the previous slide and update it

225
00:11:15,270 --> 00:11:18,480
now. As long as you understand exactly what's going on here

226
00:11:18,480 --> 00:11:20,736
because there's several steps involved, then I'm happy

227
00:11:20,736 --> 00:11:25,263
that you have mastered the art of the input() function.

