Coding Exercise for Beginners in Python| Exercise 5 | Python for Beginners #lec23

Coding Exercise for Beginners in Python| Exercise 5 | Python for Beginners #lec23

How to Calculate Remaining Days, Weeks, and Months Until 90?

Introduction to the Problem

  • The video introduces a coding exercise focused on calculating how many days, weeks, and months are left for a person if they live until 90 years old.
  • The program's output should be formatted as "You have A days, B weeks, and C months left," where A, B, and C are calculated values based on the user's current age.

Assumptions for Calculation

  • Standard assumptions for calculations include:
  • 1 year = 365 days
  • 1 year = 52 weeks
  • 1 year = 12 months
  • Leap years are excluded from these calculations for simplicity.

Input Handling in Python

  • The program will use the input() function to take the user's current age.
  • It is possible to directly typecast the input into an integer using int(input()), which simplifies code by avoiding separate conversion steps.

Calculating Remaining Time

  • To find out how many years are left until reaching age 90:
  • Calculate: years_left = 90 - current_age
  • From this value:
  • Days left: days_left = years_left * 365
  • Months left: months_left = years_left * 12
  • Weeks left: weeks_left = years_left * 52

Output Formatting with F Strings

  • The program prints a message displaying the calculated values. For example:

print(f"You have days_left days, weeks_left weeks, and months_left months left.")

  • This formatting ensures that variables are correctly displayed within strings at runtime.

Example Execution of Program

  • An example run of the program shows that entering an age of "85" results in:
  • You have 1825 days, 260 weeks, and 60 months left.
  • This demonstrates how users can easily calculate their remaining time based on their current age.
Video description

Best Python Tutorials for Beginners: https://www.youtube.com/playlist?list=PLdo5W4Nhv31bZSiqiOL5ta39vSnBxpOPT ********************************************* Connect & Contact Me: Jenny's Lecturers Hindi: https://www.youtube.com/@JennysLecturesHINDI My Second Channel Link: https://bit.ly/354n7C7 Facebook: https://www.facebook.com/Jennys-Lectures-CSIT-Netjrf-316814368950701/ Quora: https://www.quora.com/profile/Jayanti-Khatri-Lamba Instagram: https://www.instagram.com/jayantikhatrilamba/ Twitter: https://twitter.com/KhatriJenny ******************************************* More Playlists: Programming in C Tutorials: https://www.youtube.com/playlist?list=PLdo5W4Nhv31a8UcMN9-35ghv8qyFWD9_S C++ Tutorials for beginners: https://www.youtube.com/watch?v=KYxLEDF6kjs&list=PLdo5W4Nhv31YU5Wx1dopka58teWP9aCee Placement Series: https://www.youtube.com/playlist?list=PLdo5W4Nhv31YvlDpJhvOYbM9Ap8UypgEy Data Structures and Algorithms: https: https://www.youtube.com/playlist?list=PLdo5W4Nhv31bbKJzrsKfMpo_grxuLl8LU Design and Analysis of Algorithms(DAA): https://www.youtube.com/playlist?list=PLdo5W4Nhv31ZTn2P9vF02bkb3SC8uiUUn Dynamic Programming: https://www.youtube.com/playlist?list=PLdo5W4Nhv31aBrJE1WS4MR9LRfbmZrAQu Operating Systems tutorials: //www.youtube.com/playlist?list=PLdo5W4Nhv31a5ucW_S1K3-x6ztBRD-PNa DBMS Tutorials: https://www.youtube.com/playlist?list=PLdo5W4Nhv31b33kF46f9aFjoJPOkdlsRc #coding #pythonforbeginners #python #jennyslectures #pythonprogramming