1
00:00:01,219 --> 00:00:03,090
Are you looking to find true love?

2
00:00:03,090 --> 00:00:06,540
Well, this coding exercise will be able to help you

3
00:00:06,540 --> 00:00:07,860
with just that.

4
00:00:07,860 --> 00:00:11,730
This challenge is to create a love calculator.

5
00:00:11,730 --> 00:00:15,450
You're going to write a program that tests the compatibility

6
00:00:15,450 --> 00:00:17,310
between two people.

7
00:00:17,310 --> 00:00:19,650
It doesn't really matter if you believe this or not,

8
00:00:19,650 --> 00:00:23,760
we're going to use it to test out our programming skills.

9
00:00:23,760 --> 00:00:27,360
There are many ways of working out the love-score

10
00:00:27,360 --> 00:00:28,710
between two people,

11
00:00:28,710 --> 00:00:30,844
and if you've ever been to high school,

12
00:00:30,844 --> 00:00:35,520
you might have encountered one of these methods.

13
00:00:35,520 --> 00:00:40,140
This method that I've put into this coding exercise comes

14
00:00:40,140 --> 00:00:45,140
from the well-known and well-established, respectable source

15
00:00:45,365 --> 00:00:47,670
of a Buzzfeed article.

16
00:00:47,670 --> 00:00:50,670
And essentially, it works like this.

17
00:00:50,670 --> 00:00:53,168
So you take both people's names and you check

18
00:00:53,168 --> 00:00:57,600
for the number of times the letters in the word true occurs.

19
00:00:57,600 --> 00:00:59,670
So, T-R-U-E

20
00:00:59,670 --> 00:01:02,220
and then you check for the number of times letters

21
00:01:02,220 --> 00:01:06,240
in the word love occurs, so L-O-V-E, and then,

22
00:01:06,240 --> 00:01:09,810
you combine these two numbers to make a two digit number

23
00:01:09,810 --> 00:01:12,780
and that is your love score percentage.

24
00:01:12,780 --> 00:01:15,570
What we're going to do is we're also

25
00:01:15,570 --> 00:01:17,670
going to give people an interpretation.

26
00:01:17,670 --> 00:01:21,594
So if their love score is less than 10 or greater than 90,

27
00:01:21,594 --> 00:01:23,610
then we're going to send them the message

28
00:01:23,610 --> 00:01:26,040
saying, "Your score is *x*

29
00:01:26,040 --> 00:01:28,380
you go together like coke and mentos."

30
00:01:28,380 --> 00:01:30,750
And then for people with a love score between 40 and 50,

31
00:01:30,750 --> 00:01:32,160
which is kind of on the fence,

32
00:01:32,160 --> 00:01:36,600
we say, "Your love score is *y*, you are all right together.

33
00:01:36,600 --> 00:01:40,020
And then finally, if none of those conditions are true

34
00:01:40,020 --> 00:01:41,820
and people are sort of somewhere

35
00:01:41,820 --> 00:01:44,678
between 20 and 40 and 50 and 90,

36
00:01:44,678 --> 00:01:49,260
then we'll just tell them, "Your score is..." whatever it is.

37
00:01:49,260 --> 00:01:51,420
If you take a look in the description box,

38
00:01:51,420 --> 00:01:54,630
you'll see an example of how we've worked out

39
00:01:54,630 --> 00:01:57,330
name1, which is my name and name2,

40
00:01:57,330 --> 00:01:58,770
which is Jack Bauer.

41
00:01:58,770 --> 00:02:03,150
And you can see that T-R-U-E occurs a total

42
00:02:03,150 --> 00:02:06,480
of 5 times in both of our names,

43
00:02:06,480 --> 00:02:09,509
and L-O-V-E occurs a total of 3 times

44
00:02:09,509 --> 00:02:10,800
in both of our names

45
00:02:10,800 --> 00:02:15,270
and so the final love score is 53, which is neither here

46
00:02:15,270 --> 00:02:18,245
nor there, which is not fantastic, but hey,

47
00:02:18,245 --> 00:02:19,770
it is what it is.

48
00:02:19,770 --> 00:02:21,720
And so that means our program

49
00:02:21,720 --> 00:02:23,340
is just simply going to print out the score.

50
00:02:23,340 --> 00:02:26,400
"Your score is 53."

51
00:02:26,400 --> 00:02:28,830
You can take a look at some other examples that I've got

52
00:02:28,830 --> 00:02:31,560
in here to check against,

53
00:02:31,560 --> 00:02:33,618
and also I've got some hints in there

54
00:02:33,618 --> 00:02:36,620
and some scores for different names.

55
00:02:36,620 --> 00:02:40,380
This is a difficult challenge, and as I said before,

56
00:02:40,380 --> 00:02:42,459
if you get stuck on logic, try writing out

57
00:02:42,459 --> 00:02:44,520
your own flow chart program

58
00:02:44,520 --> 00:02:47,518
before you actually go and commit it to code,

59
00:02:47,518 --> 00:02:52,200
otherwise, just try things, test things, see if it works

60
00:02:52,200 --> 00:02:55,590
and you can try out the different variations

61
00:02:55,590 --> 00:02:59,010
at the bottom of the description pane, Brad Pitt,

62
00:02:59,010 --> 00:03:00,600
Jennifer Aniston, Prince William,

63
00:03:00,600 --> 00:03:03,930
Kate Middleton, et cetera, and make sure that your output

64
00:03:03,930 --> 00:03:06,840
matches the score that's shown in that table.

65
00:03:06,840 --> 00:03:08,970
And this is just to help you make sure

66
00:03:08,970 --> 00:03:12,180
that your code is working. And when your code is working, 

67
00:03:12,180 --> 00:03:14,298
then also you have to make sure that your output

68
00:03:14,298 --> 00:03:19,050
matches what the description pane wants it to say exactly,

69
00:03:19,050 --> 00:03:22,230
so the interpretations. And I recommend just copy

70
00:03:22,230 --> 00:03:23,671
and pasting some of those interpretations

71
00:03:23,671 --> 00:03:26,820
and substituting the parts appropriately.

72
00:03:26,820 --> 00:03:28,863
So, good luck and enjoy.

73
00:03:38,700 --> 00:03:39,533
All right.

74
00:03:39,533 --> 00:03:40,710
Firstly, we know we get hold

75
00:03:40,710 --> 00:03:44,010
of the name1 and name2 in our variables name1,

76
00:03:44,010 --> 00:03:46,740
name2 on lines two and three.

77
00:03:46,740 --> 00:03:47,790
And what we're going to do

78
00:03:47,790 --> 00:03:51,930
on line five is to combine these two names together

79
00:03:51,930 --> 00:03:54,840
so that we have just a single string to check.

80
00:03:54,840 --> 00:03:58,950
We write combine names equals name1 plus name2.

81
00:03:58,950 --> 00:04:02,790
The next step is to take all of the characters

82
00:04:02,790 --> 00:04:05,063
and make sure their casing is the same

83
00:04:05,063 --> 00:04:07,230
as what we're going to check it against

84
00:04:07,230 --> 00:04:10,620
because the user might have typed in capitalized names,

85
00:04:10,620 --> 00:04:11,943
they might have put the names in all caps,

86
00:04:11,943 --> 00:04:13,883
they could have put it all in lowercase,

87
00:04:13,883 --> 00:04:15,772
we don't want all of that ambiguity.

88
00:04:15,772 --> 00:04:19,050
So we're going to check the names against lowercase letters.

89
00:04:19,050 --> 00:04:22,738
So we're also going to use the ".lower() method"

90
00:04:22,738 --> 00:04:27,480
to make our combined names into lowercase.

91
00:04:27,480 --> 00:04:31,050
That means we take our name1, name2, for example

92
00:04:31,050 --> 00:04:33,810
in the Input, we've got David Beckham, and Victoria Beckham.

93
00:04:33,810 --> 00:04:36,360
By combining it on line five, we now have

94
00:04:36,360 --> 00:04:39,056
a single variable called davidbeckhamvictoriabeckham

95
00:04:39,056 --> 00:04:42,210
and by making it lowercase,

96
00:04:42,210 --> 00:04:45,003
all of those letters are now lowercase letters.

97
00:04:45,960 --> 00:04:48,570
The next step is to calculate the first digit

98
00:04:48,570 --> 00:04:49,457
in the love score,

99
00:04:49,457 --> 00:04:53,550
which according to the rules is to check how many times

100
00:04:53,550 --> 00:04:58,290
the letter T-R-U-E occurs in both the names.

101
00:04:58,290 --> 00:05:00,630
So we're going to check it against our lower names,

102
00:05:00,630 --> 00:05:03,570
the combined lowercase names, and we're checking it

103
00:05:03,570 --> 00:05:06,720
against lowercase letters as well, t-r-u-e.

104
00:05:06,720 --> 00:05:11,329
And then, we use the "count() method" to see how many times

105
00:05:11,329 --> 00:05:15,300
that letter occurs in our combined name.

106
00:05:15,300 --> 00:05:17,910
And we add those numbers all up together in order

107
00:05:17,910 --> 00:05:21,873
to get hold of our first_digit for our love calculator.

108
00:05:22,710 --> 00:05:25,950
And similarly, we do the same thing for the second_digit.

109
00:05:25,950 --> 00:05:29,760
We count how many times the letters l-o-v-e occurs

110
00:05:29,760 --> 00:05:34,410
in the combined lowercase names, and we add all

111
00:05:34,410 --> 00:05:37,713
of those occurrences up to get our second_digit.

112
00:05:39,150 --> 00:05:41,220
Once we've got both digits,

113
00:05:41,220 --> 00:05:44,550
then we can combine them together.

114
00:05:44,550 --> 00:05:47,790
The way that this calculator works is we take

115
00:05:47,790 --> 00:05:49,860
the first_digit and the second_digit

116
00:05:49,860 --> 00:05:52,980
and we create a two-digit number.

117
00:05:52,980 --> 00:05:55,050
So we can't just add it together like maths.

118
00:05:55,050 --> 00:05:58,500
It's not like 9 + 8 equals 17,

119
00:05:58,500 --> 00:06:01,110
it's actually 9 + 8 equals 98.

120
00:06:01,110 --> 00:06:03,570
So that means, we're going to have to turn our digits,

121
00:06:03,570 --> 00:06:06,720
which are numbers into strings

122
00:06:06,720 --> 00:06:09,734
so that we combine them rather than add them up.

123
00:06:09,734 --> 00:06:14,640
To do this, we write the str() method, we wrap it

124
00:06:14,640 --> 00:06:17,845
around the digit that we want to turn into a string

125
00:06:17,845 --> 00:06:20,280
and then we use the plus sign (+)

126
00:06:20,280 --> 00:06:22,800
in order to concatenate it together

127
00:06:22,800 --> 00:06:27,123
so that they occur one after the other as if it was text.

128
00:06:28,470 --> 00:06:31,278
Now, the final step is to check the score

129
00:06:31,278 --> 00:06:34,380
against the conditions that we set out

130
00:06:34,380 --> 00:06:37,957
in the description, so we can give people an interpretation

131
00:06:37,957 --> 00:06:40,980
of their score. Because in this case,

132
00:06:40,980 --> 00:06:43,770
we're going to have to compare numbers against numbers,

133
00:06:43,770 --> 00:06:48,600
then it makes sense to turn our combined love score

134
00:06:48,600 --> 00:06:53,600
into an integer, so we wrap that combined string

135
00:06:54,196 --> 00:06:57,480
into an int() method to turn it

136
00:06:57,480 --> 00:07:01,710
into a number that we can compare against other numbers.

137
00:07:01,710 --> 00:07:03,752
All that's left to do is just to write

138
00:07:03,752 --> 00:07:05,865
an if, elif, else statement

139
00:07:05,865 --> 00:07:10,080
in order to check against the three conditions.

140
00:07:10,080 --> 00:07:13,410
If the score is less than 10 or if it's greater than 90,

141
00:07:13,410 --> 00:07:16,080
then we print the first statement.

142
00:07:16,080 --> 00:07:17,790
Otherwise, if the score is greater than

143
00:07:17,790 --> 00:07:22,470
or equal to 40 and it's less than or equal to 50,

144
00:07:22,470 --> 00:07:27,150
so between 40 and 50, then we print the second statement.

145
00:07:27,150 --> 00:07:29,572
And if all of those are not true, then else, we

146
00:07:29,572 --> 00:07:33,630
just print out their score in the third statement.

147
00:07:33,630 --> 00:07:36,660
That's all there is to this exercise.

148
00:07:36,660 --> 00:07:39,270
If you had any issues, then go back

149
00:07:39,270 --> 00:07:40,560
to the previous slide and see

150
00:07:40,560 --> 00:07:43,653
if you can fix your code to make it pass all the tests.

