File tree Expand file tree Collapse file tree
Dog Age Calculator (by AdyaTech) Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Request input from the user to provide a dog's age in human years and convert it to an integer
2+ h_age = int (input ("Input a dog's age in human years: " ))
3+
4+ # Check if the entered age is less than zero; if true, display an error message and exit the program
5+ if h_age < 0 :
6+ print ("Age must be a positive number." )
7+ exit ()
8+ # If the entered age is 2 years or less, calculate the dog's age in dog's years using the formula 10.5 times the human years
9+ elif h_age <= 2 :
10+ d_age = h_age * 10.5
11+ # For ages greater than 2, calculate the dog's age in dog's years using the formula 21 plus 4 times the remaining human years after 2
12+ else :
13+ d_age = 21 + (h_age - 2 ) * 4
14+
15+ # Display the calculated dog's age in dog's years
16+ print ("The dog's age in dog's years is" , d_age )
You can’t perform that action at this time.
0 commit comments