Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #Exercise-1
  2.  
  3. #Create a program that asks the user to enter their name and their age. Print out a message addressed to them that tells them the year that they will turn 100 years old.
  4.  
  5. #Extra:
  6. #1. Add on to the previous program by asking the user for another number and printing out that many copies of the previous message.
  7. #2. Print out that many copies of the previous message on separate lines.
  8.  
  9. #import datetime
  10. import datetime
  11.  
  12. #input name (string) and age (integer)
  13. name = input('Tell me your name: ')
  14. age = int(input('Tell me your age: '))
  15.  
  16. #get the current time
  17. now = datetime.datetime.now()
  18.  
  19. #calculate the age difference
  20. yrs = 100 - age
  21.  
  22. #show when that person turn 100 years old
  23. res = 'Hi ' + name + ', you will turn 100 years old in ' + str(now.year+yrs)
  24. print(res)
  25.  
  26. #input any number and create a number copies of previous message
  27. num = int(input('Input any number of result copies: '))
  28. for x in range(num):
  29. print(res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement