1
00:00:00,630 --> 00:00:05,110
Great, as I mentioned previously in the
previous video now we're going to

2
00:00:05,110 --> 00:00:12,610
implement an extra input user input
message into the program. So instead of

3
00:00:12,610 --> 00:00:18,069
passing, returning this string basically
what I want to return is an input

4
00:00:18,069 --> 00:00:24,749
message so if the program finds out that
the user passed a word that has a

5
00:00:24,749 --> 00:00:30,789
similarity, similar words in the
dictionary, then you want to ask the user to

6
00:00:30,789 --> 00:00:44,050
enter Y or N. So how do you do that? Well,
with an input function of course. Like

7
00:00:44,050 --> 00:01:00,300
that. So let's add another message after
this. Enter Y if yes, if yes or N if no,

8
00:01:00,300 --> 00:01:09,579
so basically whatever the user enters,
you need to process that input. That

9
00:01:09,579 --> 00:01:17,259
input, so Y or N they will be basically
stored in a variable but not yet so in

10
00:01:17,259 --> 00:01:22,000
this configuration that we have here,
nothing will be storing during the

11
00:01:22,000 --> 00:01:26,409
variable it will it will just be a value
on the fly, so you need to store this in

12
00:01:26,409 --> 00:01:35,020
a variable. Let's say YN, so for yes
and no equals to that. So now you

13
00:01:35,020 --> 00:01:40,570
either Y or N will be stored in the YN
variable and you need to process that

14
00:01:40,570 --> 00:01:50,150
variable so if YN equals to yes,
what do we need to do?

15
00:01:50,150 --> 00:02:00,200
So if the user meant to say rain, then we
return data. Here we need to pass the

16
00:02:00,200 --> 00:02:06,620
correct word. The correct word, we get
the correct word from these expression

17
00:02:06,620 --> 00:02:11,060
so get_close_matches will give
us the best match and we need to pass

18
00:02:11,060 --> 00:02:16,670
that match into the data dictionary so
we get a value, the definition for

19
00:02:16,670 --> 00:02:24,170
rain because� So we use that match
because the user agreed that the best match

20
00:02:24,170 --> 00:02:30,740
was rain so we message, so this
will be replaced by rain and the user agreed

21
00:02:30,740 --> 00:02:36,050
for that. I hope this is clear. Please
ask questions if this is complicated.

22
00:02:36,050 --> 00:02:43,310
I'll be happy to answer you. So if yes,
then return this. Let me check this

23
00:02:43,310 --> 00:02:51,110
intermediate step. Sorry, I used the
equal operator here which is an

24
00:02:51,110 --> 00:02:57,290
assignment operator so you need to check
to use the comparison operator which is

25
00:02:57,290 --> 00:03:02,540
constructed of two equal operators. Save
the script again and go ahead, enter

26
00:03:02,540 --> 00:03:13,030
word rainn. Did you mean rain instead?
Enter Y if yes N if no. Let me enter Y.

27
00:03:13,030 --> 00:03:20,510
And yeah, we correctly get the
definitions for rain, great! Maybe I need

28
00:03:20,510 --> 00:03:27,950
to improve the message here. Delete the
dot and use a colon there and space and

29
00:03:27,950 --> 00:03:36,830
that should be better. If you pass rain
again and if you pass yes or no, you just

30
00:03:36,830 --> 00:03:45,769
say N, you get none because you are not
taking into consideration the N string,

31
00:03:45,769 --> 00:03:50,690
so you get none because the function is
not returning anything. You know what

32
00:03:50,690 --> 00:03:57,410
happened here is the user passed
rain in here

33
00:03:57,410 --> 00:04:06,530
so word is equal to rain. Word is passed
in here so this Y is equal to rain.

34
00:04:06,530 --> 00:04:16,690
And then we check if rain in data
is not in data because it's with two Ns,

35
00:04:16,690 --> 00:04:22,310
right? So this is not executed, the
function does not execute this statement.

36
00:04:22,310 --> 00:04:28,460
It doesn't return the definition for
rain, but it goes to this statement and

37
00:04:28,460 --> 00:04:34,730
this finds a similarity, so the list is
greater than zero and then it goes and

38
00:04:34,730 --> 00:04:41,870
executes this, so that's why we got this
other input message here. And then we

39
00:04:41,870 --> 00:04:50,200
continue there, so we are indenting under
elif, we have another nested conditional

40
00:04:50,200 --> 00:04:57,170
which is no problem, but be careful.
You need to indent it so this is one

41
00:04:57,170 --> 00:05:03,920
level of indentation deeper than this
one in here. So here we are if the user

42
00:05:03,920 --> 00:05:11,120
passed Y we return this statement. If we
use a passes everything else, then you

43
00:05:11,120 --> 00:05:17,180
are not counting for that particular
scenario, therefore there is no return

44
00:05:17,180 --> 00:05:22,820
statement executed, so the program will end
here and it will return none because

45
00:05:22,820 --> 00:05:27,650
nothing was returned. This will also not
be executed because this is one level of

46
00:05:27,650 --> 00:05:33,290
indentation with this one and since this
it was executed the program never goes

47
00:05:33,290 --> 00:05:43,160
to this level here. So what we need to do
is we need to count for other user inputs

48
00:05:43,160 --> 00:05:51,800
such as n. In that case if the user enters
N, well all we can do is

49
00:05:51,800 --> 00:06:01,479
return the message: �The word doesn't exist.
Please double check it�.

50
00:06:01,479 --> 00:06:11,409
Which is the same as this one
in here. And we need to count for another

51
00:06:11,409 --> 00:06:15,870
condition. You know the user may pass Y,
may pass N, but they may also pass

52
00:06:15,870 --> 00:06:21,219
another random string, and you don't want
the program to return none. You want the

53
00:06:21,219 --> 00:06:32,439
program to return a message such as:
�We didn't understand your query�. That's it.

54
00:06:32,439 --> 00:06:38,050
That's all you can do. Or your
entry. Maybe that's better.

55
00:06:38,050 --> 00:06:43,240
So this is the program. Again we have the
scenario when the user enters rain

56
00:06:43,240 --> 00:06:48,550
exactly and this will be executed in
that case. And the scenario when the user

57
00:06:48,550 --> 00:06:56,979
enters a word which does not have any
match so is like cacacaca.

58
00:06:56,979 --> 00:07:05,349
Something like that. In that case, this
will not be executed. Yeah, that's it. Let

59
00:07:05,349 --> 00:07:15,029
me test the program now. Enter a word.
Rain. We get the definitions for rain.

60
00:07:15,029 --> 00:07:20,560
Again enter word. Rainn, like that. Did you
mean rain instead? Enter Y if yes, enter N

61
00:07:20,560 --> 00:07:30,129
if no. Let me try yes and we get the
definition correctly. Rainn, enter N

62
00:07:30,129 --> 00:07:35,020
for no. The word doesn't exist. Please
double check it. Okay, that was good as

63
00:07:35,020 --> 00:07:45,459
well. So we got this executed. The other
scenario would be like that. So instead

64
00:07:45,459 --> 00:07:50,830
of entering Y and N, you just type
in something and you say: �We didn't

65
00:07:50,830 --> 00:07:58,089
understand your entry�. Good. And
the other scenario is when you enter a

66
00:07:58,089 --> 00:08:04,149
world that does not have any match at
all and in that case this will be

67
00:08:04,149 --> 00:08:09,579
executed immediately.
That's it. By the way even if you enter

68
00:08:09,579 --> 00:08:14,529
numbers, let's say 1. The word doesn't exist
because it's not included in the

69
00:08:14,529 --> 00:08:18,250
dictionary.
And I think our program is quite smart

70
00:08:18,250 --> 00:08:24,160
now. It's considering lots of scenarios
there and it's quite user friendly

71
00:08:24,160 --> 00:08:30,130
I'd say, however there is one last thing
that we can improve and that's the way

72
00:08:30,130 --> 00:08:36,280
that the user, that the program
displays the definition. So when you

73
00:08:36,280 --> 00:08:45,880
pass let's say tree, tree also
has two definitions. Let's pass

74
00:08:45,880 --> 00:08:53,320
a word that has one definition. Structure
maybe. No, this has three definitions, all

75
00:08:53,320 --> 00:09:01,900
right. Pyramid. This also has two
definitions. Anyway you get the idea.

76
00:09:01,900 --> 00:09:06,640
I was trying to get, to fund a word that
has one definition, but basically what

77
00:09:06,640 --> 00:09:12,450
you get with such a word that has
one definition, is you still get a list

78
00:09:12,450 --> 00:09:17,080
which ends in here, so it doesn't have a
comma and it doesn't have any other items

79
00:09:17,080 --> 00:09:20,830
so it's a list with one item. And when
you have a word that has more than one

80
00:09:20,830 --> 00:09:27,430
meaning, you get this list with more
than one item. So you don't want to show

81
00:09:27,430 --> 00:09:32,770
you the user a list with brackets
like that. The best thing to do, to

82
00:09:32,770 --> 00:09:39,190
show to the user is you know, if you have
one meaning, one definition for the word

83
00:09:39,190 --> 00:09:47,440
you just show this definition. No quotes,
no square brackets, just the definition.

84
00:09:47,440 --> 00:09:52,780
And if you have more than one definition,
you only show, you show one definition

85
00:09:52,780 --> 00:09:58,990
per line, so basically you have like
multiple lies with definitions and yeah,

86
00:09:58,990 --> 00:10:05,680
we need to implement that to say
finally that our program is good and can

87
00:10:05,680 --> 00:10:13,510
be used by anyone and the output is easy to
read. So think about that. We're going to

88
00:10:13,510 --> 00:10:17,000
implement it in the next lecture. See you!

