PDF download Download Article PDF download Download Article

Python is a simple yet powerful programming language to learn. It accommodates all levels of programmers from beginners to advanced programmers. Python is flexible and can work on available operating systems e.g., Mac, Windows, and Linux. Have you learned about the bare basics of python but are confused on how to apply them? Well, this article shows you how to make a program that calculates your total days, minutes, and seconds you have been alive! It is a very simple program that demonstrates how some things work in this programming language. Note that this is for users who have a basic understanding of python.

  1. So you have to use the print function. Type below codes:

    print("Let's see how long you have lived in days, minutes and seconds.")
    
    Advertisement
  2. It's nice to know what the user's name is, so type this in line 2:
      name = input("name: ")
      
    • The variable "name" has now been replaced by the user's input.
  3. You need to know the age, now you do the same thing as above except you have to use the "int" function, because the user will enter a number, like this:
      print("now enter your age")
      age = int(input("age: "))
      
    • The variable "age" has now been replaced by the user's input.
    • days = age * 365
      minutes = age * 525948     
      seconds = age * 31556926
      
    • Once you have written this, Python automatically changes the values for days, minutes, and seconds, based on the user's input of age.
    • print(name, "has been alive for", days,"days", minutes, "minutes and", seconds, "seconds!  Wow!")
      
  4. you made a real program that serves a purpose! Save it and run it by going to 'run' and 'run module'. Try it out for yourself!
  5. Advertisement


Community Q&A

Search
Add New Question
  • Question
    What do I do if I get errors while trying to create a simple program?
    Community Answer
    Community Answer
    Try to check and read over your code. Are your variable names correct? Are there any misused brackets or symbols? Usually it will be highlighted if this is the case. If it is, try to figure out how to fix it the best you can.
  • Question
    The program closes after I type my name and never shows me how many seconds I lived. I copied and pasted everything here. I am using Python 2.7 and can't get a newer version as I use Win XP. Do you have any suggestions for me?
    Community Answer
    Community Answer
    Under python 2.7, 'input()' asks for an input to execute (a python statement). The exemple above is for python 3 which disable the direct execution of code via 'input()'. So, if you need the user to give you an input, use 'raw_input()' instead of 'input()'
  • Question
    How do I write a comment?
    Cluster Duck
    Community Answer
    There are two ways to write a comment in python. A # is used for a one line comment. A """ is used for a multi line comment.
See more answers
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement

Tips

Submit a Tip
All tip submissions are carefully reviewed before being published
Name
Please provide your name and last initial
Thanks for submitting a tip for review!

You Might Also Like

Start Programming in PythonStart Programming in Python
Use Windows Command Prompt to Run a Python FileUse Windows Command Prompt to Run a Python File
Update Pip Upgrade Pip: Quick Guide for Beginners & Experts
Open a Python FileOpen a Python File
Comment Out Multiple Lines in Python Comment Out Multiple Lines in Python: Formatting & Shortcuts
Pip Uninstall Package Uninstall a Python Package With Pip: Step-by-Step Guide
Install Pip on Mac3 Easy Ways to Download & Install Pip on Your Mac
Check Python Version on PC or Mac See the Python Version on Mac, Windows, and Linux
Change the Font Size in Python ShellChange the Font Size in Python Shell
Uninstall PythonUninstall Python
Program a Game in Python with PygameProgram a Game in Python with Pygame
Make a Countdown Program in Python Code a Python Countdown Timer: Step-by-Step Guide
Write a Coin Flipping Program on PythonWrite a Coin Flipping Program on Python
Create Loops in Python Create Loops in Python
Advertisement

Expert Interview

Thanks for reading our article! If you’d like to learn more about programming, check out our in-depth interview with Kevin Burnett.

About This Article

Kevin Burnett
Co-authored by:
Software Developer
This article was co-authored by Kevin Burnett. Kevin Burnett is a Software Developer with over 20 years of professional experience. He works for SpiffWorkflow, a Python Process Automation tool for organizations. Prior to SpiffWorkflow, he spent the majority of his career at Rosetta Stone, a language-learning software company. He has experience with both front and back-end development and works primarily in Python, Ruby, and JavaScript. He attended the first RailsConf and the most recent PyCon US. He received an MBA and a BA in Computer Science and Spanish from Eastern Mennonite University. This article has been viewed 250,965 times.
How helpful is this?
Co-authors: 29
Updated: January 17, 2024
Views: 250,965
Categories: Python
Thanks to all authors for creating a page that has been read 250,965 times.

Reader Success Stories

  • Nathan Mahoney

    Nathan Mahoney

    Mar 3, 2017

    "It was very helpful. I still use it in school, so it definitely helped my education, cheers!"
Share your story

Is this article up to date?

Advertisement