Practice Problems 2(Housefly Age)

Q.Houseflies have an approximate life of four weeks. Given the number of days a housefly lived, design an algorithm and write the Python code to determine its approximate age in seconds. Check for boundary conditions and print ‘Invalid input’ if condition is not satisfied. For example, if a housefly lived for 21 days then its approximate age in seconds is 21*24*60*60 is 1814400.



Input:

Get the age of housefly in days and store it in age variable



Processing:

age_seconds = age*24*60*60



Output:

Display the age in seconds



Algorithm:

Step1. Get the age of housefly in days and store it in age variable

Step2. Check if the age is greater than 0 and less than 28 days if yes then proceed to next step if no print ‘invalid input’ and ask the user to enter a valid input

Step3. age in seconds is equal to age * 24 * 60 * 60

Step4. Display the age in seconds

Step5. End

Program:
age = int(input())
if age<0 or age>=28:
    print("Invalid input")
else:  
    age_seconds = age * 24 * 60 *60

    print(age_seconds)


Flowchart:

AgeDupl.png

To edit this flowchart click on this link

No comments:

Post a Comment

Bonus Practice Problems(GMT To IST)

IST (Indian Standard Time) is 5 hours 30 minutes ahead of GMT(Greenwich Mean Time). Develop an algorithm and write the Python code to find...