top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

Python apps: know your age

Writer's picture: Imene MaallemImene Maallem


These days, developers are highly likely to be working on a mobile or web application.Python is a rather universal programming language that is appropriate for solving a wide range of tasks. Python is often used as a support language for software developers,Python doesn't have built-in mobile development capabilities. for build control and management, testing, and in many other ways


# know you age !

#This code was created to determine the users' age by entering the birth year and prior to whether the person have celebrated his birthday or not :

We are going to use first the input function which allows the user to choose a digit from 2 to 10 and write it :


num=input("enter a digit from 2 to 10:")

Then we generate the same function in order to ask from the user whether he has celebrated his birthday or not :


birth=input("Have you already celebrated your birthday ?:")

if he says yes, we do use if statement and do some excplicit calculations :

if birth=="yes":

a= (int(num)*2+5)*50+1771

We then generate same i=function inorder to enter his year of birth :


  year=input("enter the year of birth:")
  fin= a- int(year)
  fina= str(fin)
  final=int(fina[1]+ fina[2])

Finally, we print the final age


  print("your age is" , final)

In case the user has not already celebrated his birthday , we use elif statement and perform some calculations


elif birth== "no":
   a= (int(num)*2+5)*50+1771
   year=input("enter the year of birth:")
   fin= a- int(year)
   fina= str(fin)
   final=int(fina[1]+ fina[2])
   print("your age is" , final)


Let's try the code together :



num=input("enter a digit from 2 to 10:")
birth=input("Have you already celebrated your birthday ?:")
if birth=="yes":
  a= (int(num)*2+5)*50+1771
  year=input("enter the year of birth:")
  fin= a- int(year)
  fina= str(fin)
  final=int(fina[1]+ fina[2])
  print("your age is" , final)
elif birth== "no":
   a= (int(num)*2+5)*50+1771
   year=input("enter the year of birth:")
   fin= a- int(year)
   fina= str(fin)
   final=int(fina[1]+ fina[2])
   print("your age is" , final)

0 comments

Recent Posts

See All

Comments


COURSES, PROGRAMS & CERTIFICATIONS

 

Advanced Business Analytics Specialization

Applied Data Science with Python (University of Michigan)

Data Analyst Professional Certificate (IBM)

Data Science Professional Certificate (IBM)

Data Science Specialization (John Hopkins University)

Data Science with Python Certification Training 

Data Scientist Career Path

Data Scientist Nano Degree Program

Data Scientist Program

Deep Learning Specialization

Machine Learning Course (Andrew Ng @ Stanford)

Machine Learning, Data Science and Deep Learning

Machine Learning Specialization (University of Washington)

Master Python for Data Science

Mathematics for Machine Learning (Imperial College London)

Programming with Python

Python for Everybody Specialization (University of Michigan)

Python Machine Learning Certification Training

Reinforcement Learning Specialization (University of Alberta)

Join our mailing list

Data Insight participates in affiliate programs and may sometimes get a commission through purchases made through our links without any additional cost to our visitors.

bottom of page