Make a Program with random function in Python

Make a Program  "How Many Days you have ? ?" in Python. We Use 2 Method for this program 1st is Simple program and 2nd method is use Random Module. 

In this program user provides the current age and program will calculate the left age, in simple method we are taking the max age 100 yrs and then providing the calculation. 

SIMPLE METHOD:-

age = int(input(“What is your current age? “))
age2 = 100 – age

# we use age2 a variable and set a permanent number.

day = age2 * 365
week = round(age2* 52)
month = round(age2 * 12)

print(f”you have {day} days, {week} Weeks and {month} months left.”)

 

OUTPUT:-

But, The Problem is , if you again Enter your age then always same Output kind above Screenshot. 
So, Lets make Interesting Program using Random Module. 
What Is Random Module  - This module implements pseudo-random number generators for various distributions. For integers, there is uniform selection from a range. For sequences, there is uniform selection of a random element, a function to generate a random permutation of a list in-place, and a function for random sampling without replacement. On the real line, there are functions to compute uniform, normal (Gaussian), lognormal, negative exponential, gamma, and beta distributions. For generating distributions of angles, the von Mises distribution is available.
Following Below: - 
random.randint(ab) Return a random integer N such that a <= N <= b. Alias for randrange(a, b+1).
For More Information About Random Module you can visit Official Python Documentation site. 
https://docs.python.org/3/library/random.html#random.randrange

In this program user provides the current age and program will calculate the left age, but here is one change and we are taking the max age randomly like we don’t know which year is last year and then providing the calculation.

2nd METHOD Using Random Module:-

# Always mention Import Random when you work with random number Like below:

import random

age = int(input(“What is your current age? “))
age2 = random.randint(age,100)

result = age2 – age
day = result * 365
week = round(result* 52)
month = round(result * 12)

print(f”you have {day} days, {week} Weeks and {month} months left.”)

OUTPUT-1

OUTPUT-2

The Best part in this Random Program, always Show different output.

Thank You ! ❤️

 

If you want to know about IF / ELIF / ELSE condition click on the link given below;

https://www.devopscheetah.com/how-to-create-own-bmi-calculator-in-python/

2 thoughts on “Make a Program with random function in Python”

Leave a Reply

Your email address will not be published. Required fields are marked *