Best Corporate Training & Consulting For Tableau, PowerBI, QlikSense, Python , Data Analytics & Data Science - ML, DL in Gurgaon
Categories: Academics

Learning Python by Simple Real World Problems : Problem#1

Problem Statement :

Priyanka and Brooklyn are two python programmers. Priyanka writes more lines of code than Brooklyn per day. Brooklyn being very enthusiastic person decided to improve on herself. Currently, Brooklyn is ‘D’ problems behind Priyanka. So, Brooklyn increased her speed to writing ‘K’ lines of code per day. Priyanka continue to write her code at ‘A’ lines of code per day.

Write a python program that accepts three arguments i.e. D, K and A. and returns the number of days Brooklyn will take to bypass Priyanka.

 

Solution & Explanation:

 

Suppose Priyanka have written 200 lines of code and Brooklyn have written 150 lines of codes. Current speed of Priyanka is 20 lines per day and now Brooklyn has increased her speed to 25 lines per day.

So, based on this following are our inputs:

D = 200 – 150 = 50

K = 25

A = 20

So, Brooklyn has to cover 50 lines of code in total. Each day Brooklyn can cover the difference in speed with Priyanka i.e. each day Brooklyn can cover (25-20) i.e. 5 lines of code per day.

Since she has to cover 50 lines, so total number of days required to surpass Priyanka will be:

( D / (K – A) ) + 1

The point here must be noted that if the value of A > K this means speed of Priyanka is still greater than that of Brooklyn then Brooklyn will not be able to surpass Priyanka. Mathematically it will result in negative answer. SO, while writing the code we should put a check that value of K entered should be greater than value of A in order to get correct outcome.

 

Program

We will be using Anaconda Python distribution version 2.7 and Spyder IDE to write the python program. You can install python and download Anaconda from the Anaconda website

https://www.continuum.io/downloads

Once you open Spyder , it would look like below :

The first step is to take input from user for the three values D, A and K. The user can be made to enter

Input from python by using input function. The text in the quotes can be written in the input function which will be displayed before user is prompted to enter the input. The input text entered by user is accepted in python as a string. So, we also need to convert it into an integer type. Below is the screenshot to do it:

 

Next is to check the whether the value of K is greater than A or not. So, if the value of K is less than A then more computation is possible and program should exit. So, to exit the program we need to import the library sys. And use the sys.exit() function to quit the program. This can be done programmatically as follows:

Now since we have checked the constraint we can proceed to compute the desired outcome. The code can be written as follows:

Now we will run the program. IN Spyder python can be executed the clicking the green arrow at the icon bar as follows:

By clicking this following is the execution outcome of the code:

Hence the answer is 11 Days as can be seen is the above screenshot.

Akriti Lal

Akriti Lal is a Data Analytics and Data Visualization maven with a Decade of experience in different industry verticals.She has worked extensively on data analytics & data visualization using tools like Tableau , Microsoft Power BI , Python , Microsoft SQL Server , Qlik Sense , Microsoft Power Pivot , Power Excel & Looker . Reach out at info@instrovate.com or Whatsapp / Call at +91 74289 52788

Recent Posts

PL-100T00-A: Microsoft Power Platform App Maker

3 Days ( 24 Hrs ) Instructor-led trainingIntermediateEnglish We wil be providing you Microsoft Official Course…

3 years ago

MB-910T00: Microsoft Certified: Dynamics 365 Fundamentals (CRM)

2 DaysInstructor-led trainingBeginnerEnglish Skills gained Describe the capabilities and functionality of Dynamics 365 MarketingDescribe the…

3 years ago

PL-400T00-A: Microsoft Power Platform Developer

5 Days ( 40 Hrs ) Instructor-led trainingIntermediateEnglish We wil be providing you Microsoft Official Course…

3 years ago

PL-200T00: Microsoft Power Platform Functional Consultant

5 Days ( 40 Hrs ) Instructor-led trainingIntermediateEnglish We wil be providing you Microsoft Official…

3 years ago

PL-900T00: Microsoft Power Platform Fundamentals

2 DaysInstructor-led trainingBeginnerEnglish Prerequisites No prerequisites for this course Skills gained Describe Microsoft Power Platform…

3 years ago

Power Platform Training – 3 Days – Power Apps , Power Automate Flows , Power Virtual Agents

Course Content Day-1: Power Platform Introduction Power Platform Introduction.Components of Power PlatformConnectors, Triggers & ActionsOverview…

3 years ago