-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMethods2.py
More file actions
35 lines (28 loc) · 1.06 KB
/
Methods2.py
File metadata and controls
35 lines (28 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
################################################################################
# TITLE: Using Methods in Python
# DESCRIPTION: Stores user input into variables and outputs the variables
# to the user.
################################################################################
# Need to include this to get the current date/time
from datetime import datetime
# MAIN METHOD
def main():
name = input('What is your name? ')
birthYear = input('What year were you born (4-digit)? ')
print('Hello',name)
# CALL METHOD 2 and return how old you are
print('You are',calculateAge(birthYear))
print('Bye!')
# METHOD 2
def calculateAge(x):
# Get the current date
now = datetime.now()
# Get the current year
currentYear = now.year
# Figure out how old they are and convert x into a whole number variable
yourAge = currentYear - int(x)
# Send your age back to where it was called from using return
return yourAge
if __name__ == "__main__":
# Here we start the program by calling the main method
main()