Skip to content

Instantly share code, notes, and snippets.

@roman-on
Created April 9, 2020 16:34
Show Gist options
  • Save roman-on/c3306e5657b23317790cbf74636d4613 to your computer and use it in GitHub Desktop.
Save roman-on/c3306e5657b23317790cbf74636d4613 to your computer and use it in GitHub Desktop.
"The Three Little Pigs"
"""
Legend of "The Three Little Pigs" tells of three pigs that lived under the threat of a werewolf. With a view to providing shelter for themselves, they began to gather building materials together.
Write a plan that shows the total number of pigs collected by the pigs, and the number of bricks available to each pig, according to the instructions below.
Guidelines
The program will receive as a three-digit input (assume the input is correct). Each number in this number represents the number of bricks collected by another pig.
The program will print the following output:
1. The total number of bricks (the amount) collected by the piglets (ie the sum of the three digits)
2. The number of bricks that each pig will receive if they divide the total number of bricks equally among everyone
3. The remainder of the brick division (as divided in the previous section)
4. True if the amount is split between the three pigs without residue, and False otherwise. Please note, no condition instruction is used
Do not use loops.
Sample run
>>> Enter three digits (each digit for one pig): 124
7
2
1
False
"""
# USE NUMBER - 124
number = int(input("Insert 3 digits number: "))
hundreds = number // 100
print("hundreds:" + str(hundreds))
tens = (number // 10) % 10
print("tens:" + str(tens))
units = number % 10
print("units:" + str(units))
sum_of_numbers = hundreds + tens + units
print("Sum: " + str(sum_of_numbers))
print("The number of bricks that each pig will receive if they divide the total number of bricks is equal among all:" , (sum_of_numbers)//3 )
print("The remainder of the brick division:", (sum_of_numbers)%3)
print("True if the amount is split between the three pigs without residue, and False otherwise:", (sum_of_numbers)//3==0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment