Skip to content

Instantly share code, notes, and snippets.

@Elixsa
Last active February 9, 2025 15:55
Show Gist options
  • Save Elixsa/c431a339f3ca6697f5e2487ba3d3f303 to your computer and use it in GitHub Desktop.
Save Elixsa/c431a339f3ca6697f5e2487ba3d3f303 to your computer and use it in GitHub Desktop.
2.5.1.9 LAB: The Digit of Life
#Some say that the Digit of Life is a digit evaluated using somebody's birthday. It's simple - you just need to sum all the digits of the date. If the result contains more than one digit, you have to repeat the addition until you get exactly one digit. For example:
#1 January 2017 = 2017 01 01
#2 + 0 + 1 + 7 + 0 + 1 + 0 + 1 = 12
#1 + 2 = 3
#3 is the digit we searched for and found.
#Your task is to write a program which:
#asks the user her/his birthday (in the format YYYYMMDD, or YYYYDDMM, or MMDDYYYY - actually, the order of the digits doesn't matter)
#outputs the Digit of Life for the date.
#Test your code using the data we've provided.
#Test data
#Sample input:
#19991229
#Sample output:
#6
#Sample input:
#20000101
#Sample output:
#4
birthdate = input("Please enter your birthdate in the format YYYYMMDD")
# if birthdate.isdigit()
singledigit = False
while singledigit == False:
birthdaydigits = []
total = 0
for char in range(len(birthdate)):
birthdaydigits.append(int(birthdate[char]))
#print(birthdaydigits)
for number in range(len(birthdaydigits)):
total += birthdaydigits[number]
if total > 9:
birthdate = str(total)
continue
else:
total = str(total)
break
print(total)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment