1
00:00:00,930 --> 00:00:02,500
Hi guys and welcome back.

2
00:00:02,500 --> 00:00:05,390
In this video we're going to building our first app.

3
00:00:05,390 --> 00:00:07,030
Think of it as a bit of a recap

4
00:00:07,030 --> 00:00:09,450
of everything we've learned so far.

5
00:00:09,450 --> 00:00:12,380
The app we're going to build will ask the users

6
00:00:12,380 --> 00:00:14,840
for their age, and then it will tell them

7
00:00:14,840 --> 00:00:17,230
how many months that age equals to.

8
00:00:17,230 --> 00:00:22,230
So for example, if they enter 10, the app will say 120

9
00:00:22,250 --> 00:00:25,420
because that's 12 months in each year of course.

10
00:00:25,420 --> 00:00:29,410
And so let's get start by asking the user for their age,

11
00:00:29,410 --> 00:00:32,340
and we will say for example, user underscore age,

12
00:00:32,340 --> 00:00:34,700
and then we're gonna use the input function

13
00:00:34,700 --> 00:00:39,233
to get the user's age, we'll say input Enter your age.

14
00:00:40,440 --> 00:00:43,450
Then remember that this is going to give you back a string,

15
00:00:43,450 --> 00:00:46,300
so we need to turn it into an integer or whole number

16
00:00:46,300 --> 00:00:48,470
so that we can do maths on it.

17
00:00:48,470 --> 00:00:53,203
So we will say something like years equal int of user age.

18
00:00:54,270 --> 00:00:57,120
Now we're gonna calculate the months that that equals to

19
00:00:57,120 --> 00:00:59,480
so that we can tell the user that information.

20
00:00:59,480 --> 00:01:03,103
So we'll say months equal years times 12.

21
00:01:04,010 --> 00:01:07,120
Finally, we're gonna print it out for the user to see.

22
00:01:07,120 --> 00:01:09,310
So you could do just print months,

23
00:01:09,310 --> 00:01:10,970
but that's not gonna tell the user a lot

24
00:01:10,970 --> 00:01:13,650
about what it actually means, this variable,

25
00:01:13,650 --> 00:01:15,470
unless they know what the programme does,

26
00:01:15,470 --> 00:01:17,100
it's not gonna be all that helpful.

27
00:01:17,100 --> 00:01:19,570
So instead, I recommend using an f string

28
00:01:19,570 --> 00:01:23,090
to print the information in a bit of a readable format.

29
00:01:23,090 --> 00:01:27,020
So we can say something like Your age, years,

30
00:01:27,020 --> 00:01:30,293
is equal to this many months.

31
00:01:32,070 --> 00:01:35,530
So if we run this file, then you get asked to enter your age

32
00:01:35,530 --> 00:01:37,810
let's say 30, and then you get,

33
00:01:37,810 --> 00:01:41,870
Your age, 30, is equal to 360 months.

34
00:01:41,870 --> 00:01:44,340
So this is our very first application

35
00:01:44,340 --> 00:01:47,020
that actually does something, and you can extend this

36
00:01:47,020 --> 00:01:49,220
further and I would encourage you to do so,

37
00:01:49,220 --> 00:01:50,790
just to play around with the code,

38
00:01:50,790 --> 00:01:54,070
and so that instead of printing out the number of months,

39
00:01:54,070 --> 00:01:55,930
you can print out the number of seconds

40
00:01:55,930 --> 00:01:57,360
that this is equal to.

41
00:01:57,360 --> 00:01:58,980
Of course the maths is gonna be slightly different,

42
00:01:58,980 --> 00:02:00,980
you're gonna have to multiply a few more things here

43
00:02:00,980 --> 00:02:02,840
to calculate the number of seconds,

44
00:02:02,840 --> 00:02:05,040
but that should let you play around

45
00:02:05,040 --> 00:02:06,400
with this code a little bit.

46
00:02:06,400 --> 00:02:08,490
Something else that you may wanna think about,

47
00:02:08,490 --> 00:02:10,880
is simplifying this code a little bit,

48
00:02:10,880 --> 00:02:13,120
'cause at the moment we've got our input

49
00:02:13,120 --> 00:02:16,330
and then we have this variable called user age,

50
00:02:16,330 --> 00:02:19,270
the user age variable is only used

51
00:02:19,270 --> 00:02:22,500
to be converted into an integer in the very next line.

52
00:02:22,500 --> 00:02:25,460
So actually, we could just put the int function

53
00:02:25,460 --> 00:02:30,130
around that input, so now what we're turning into an integer

54
00:02:30,130 --> 00:02:33,960
is the result of calling the input function

55
00:02:33,960 --> 00:02:35,690
which is gonna give us the string.

56
00:02:35,690 --> 00:02:39,750
So the value the user enters will be this,

57
00:02:39,750 --> 00:02:42,160
and then that will be turned into an integer.

58
00:02:42,160 --> 00:02:45,920
So we actually don't need this line at all,

59
00:02:45,920 --> 00:02:48,930
although we do need to use the user age

60
00:02:48,930 --> 00:02:51,090
instead of the years variable.

61
00:02:51,090 --> 00:02:52,760
And that is a little bit simpler,

62
00:02:52,760 --> 00:02:54,620
and the reason for doing that is,

63
00:02:54,620 --> 00:02:56,080
so that you don't have a variable

64
00:02:56,080 --> 00:02:58,520
that is only used as a temporary measure

65
00:02:58,520 --> 00:03:00,720
before it gets converted into another type,

66
00:03:00,720 --> 00:03:03,120
so you can put functions inside of functions

67
00:03:03,120 --> 00:03:04,400
when it makes sense, it can make your code

68
00:03:04,400 --> 00:03:07,130
a little bit less readable, but in this case,

69
00:03:07,130 --> 00:03:09,440
I think it's OK, it is simple enough

70
00:03:09,440 --> 00:03:11,890
that it should make a lot of sense.

71
00:03:11,890 --> 00:03:14,370
That's it for this video, do tackle the extension

72
00:03:14,370 --> 00:03:16,300
which is to print out the number of seconds

73
00:03:16,300 --> 00:03:18,900
instead of months, and I'll see you in the next one.

