i have if condition in program what that exact value be in that condition?What does ** (double star/asterisk) and * (star/asterisk) do for parameters?What are metaclasses in Python?What is the difference between @staticmethod and @classmethod?What does the “yield” keyword do?Does Python have a ternary conditional operator?What does if __name__ == “__main__”: do?What is __init__.py for?How do I sort a dictionary by value?Does Python have a string 'contains' substring method?How to access environment variable values?
Are there any individual aliens that have gained superpowers in the Marvel universe?
Why does independence imply zero correlation?
Second 100 amp breaker inside existing 200 amp residential panel for new detached garage
Can i enter UK for 24 hours from a Schengen area holding an Indian passport?
Prisoner on alien planet escapes by making up a story about ghost companions and wins the war
How long did the SR-71 take to get to cruising altitude?
What is the oldest commercial MS-DOS program that can run on modern versions of Windows without third-party software?
Non-misogynistic way to say “asshole”?
Find the common ancestor between two nodes of a tree
Is the continuity test limit resistance of a multimeter standard?
How can I ping multiple IP addresses at the same time?
Justifying Affordable Bespoke Spaceships
Is there any proof that high saturation and contrast makes a picture more appealing in social media?
What is the "ls" directory in my home directory?
Has a life raft ever been successfully deployed on a modern commercial flight?
Do I have to explain the mechanical superiority of the player-character within the fiction of the game?
Are there examples of rowers who also fought?
Can you use one creature for both convoke and delve for Hogaak?
What was the first third-party commercial application for MS-DOS?
What was the flower of Empress Taytu?
How to remove stain from pavement after having dropped sulfuric acid on it?
Traversing Latin America & Caribbean: A Cryptic Journey
Dates on degrees don’t make sense – will people care?
What is the most suitable position for a bishop here?
i have if condition in program what that exact value be in that condition?
What does ** (double star/asterisk) and * (star/asterisk) do for parameters?What are metaclasses in Python?What is the difference between @staticmethod and @classmethod?What does the “yield” keyword do?Does Python have a ternary conditional operator?What does if __name__ == “__main__”: do?What is __init__.py for?How do I sort a dictionary by value?Does Python have a string 'contains' substring method?How to access environment variable values?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have a while loop and if conditions in this program and output will be everything is fine. but,my problem is in if condition like if arr[i]<dep[j]
in that condition arr[i]
means arr[1]
. but dep[j]
means, I don't know the index. can anyone explain this code?
here is the code.
def bus(arr, dep, n):
arr.sort()
dep.sort()
p = 1
r = 1
i = 1
j = 0
while i < n and j < n:
if arr[i] < dep[j]:
print(arr[i], dep[j])
print(dep[j])
p += 1
print(p)
i += 1
if p > r:
r = p
print(r, p)
else:
p -= 1
print(p)
j += 1
return r
arr = [900, 940, 950, 1100, 1500, 1800]
dep = [910, 1200, 1120, 1130, 1900, 2000]
n = len(arr)
print('min no.of platforms:', bus(arr, dep, n))
python python-3.x python-2.7
add a comment |
I have a while loop and if conditions in this program and output will be everything is fine. but,my problem is in if condition like if arr[i]<dep[j]
in that condition arr[i]
means arr[1]
. but dep[j]
means, I don't know the index. can anyone explain this code?
here is the code.
def bus(arr, dep, n):
arr.sort()
dep.sort()
p = 1
r = 1
i = 1
j = 0
while i < n and j < n:
if arr[i] < dep[j]:
print(arr[i], dep[j])
print(dep[j])
p += 1
print(p)
i += 1
if p > r:
r = p
print(r, p)
else:
p -= 1
print(p)
j += 1
return r
arr = [900, 940, 950, 1100, 1500, 1800]
dep = [910, 1200, 1120, 1130, 1900, 2000]
n = len(arr)
print('min no.of platforms:', bus(arr, dep, n))
python python-3.x python-2.7
What exactly is your problem?
– DirtyBit
Mar 25 at 6:32
if arr[i]<dep[j]: print(arr[i],dep[j]) print(dep[j]) p+=1 print(p) i+=1 in this condition if arr[i]<dep[j]: the value 1120 value will be stored dep[ j ] .why exactly 1120 will be stored in this condition.
– Brahma Reddy
Mar 25 at 6:41
Why you are staring i from 1 ?
– Muthu Kumar
Mar 25 at 6:45
because i don't want to start with oth index.that's why i take 1 index.
– Brahma Reddy
Mar 25 at 6:47
add a comment |
I have a while loop and if conditions in this program and output will be everything is fine. but,my problem is in if condition like if arr[i]<dep[j]
in that condition arr[i]
means arr[1]
. but dep[j]
means, I don't know the index. can anyone explain this code?
here is the code.
def bus(arr, dep, n):
arr.sort()
dep.sort()
p = 1
r = 1
i = 1
j = 0
while i < n and j < n:
if arr[i] < dep[j]:
print(arr[i], dep[j])
print(dep[j])
p += 1
print(p)
i += 1
if p > r:
r = p
print(r, p)
else:
p -= 1
print(p)
j += 1
return r
arr = [900, 940, 950, 1100, 1500, 1800]
dep = [910, 1200, 1120, 1130, 1900, 2000]
n = len(arr)
print('min no.of platforms:', bus(arr, dep, n))
python python-3.x python-2.7
I have a while loop and if conditions in this program and output will be everything is fine. but,my problem is in if condition like if arr[i]<dep[j]
in that condition arr[i]
means arr[1]
. but dep[j]
means, I don't know the index. can anyone explain this code?
here is the code.
def bus(arr, dep, n):
arr.sort()
dep.sort()
p = 1
r = 1
i = 1
j = 0
while i < n and j < n:
if arr[i] < dep[j]:
print(arr[i], dep[j])
print(dep[j])
p += 1
print(p)
i += 1
if p > r:
r = p
print(r, p)
else:
p -= 1
print(p)
j += 1
return r
arr = [900, 940, 950, 1100, 1500, 1800]
dep = [910, 1200, 1120, 1130, 1900, 2000]
n = len(arr)
print('min no.of platforms:', bus(arr, dep, n))
python python-3.x python-2.7
python python-3.x python-2.7
edited Mar 25 at 7:01
Brahma Reddy
asked Mar 25 at 6:31
Brahma ReddyBrahma Reddy
165
165
What exactly is your problem?
– DirtyBit
Mar 25 at 6:32
if arr[i]<dep[j]: print(arr[i],dep[j]) print(dep[j]) p+=1 print(p) i+=1 in this condition if arr[i]<dep[j]: the value 1120 value will be stored dep[ j ] .why exactly 1120 will be stored in this condition.
– Brahma Reddy
Mar 25 at 6:41
Why you are staring i from 1 ?
– Muthu Kumar
Mar 25 at 6:45
because i don't want to start with oth index.that's why i take 1 index.
– Brahma Reddy
Mar 25 at 6:47
add a comment |
What exactly is your problem?
– DirtyBit
Mar 25 at 6:32
if arr[i]<dep[j]: print(arr[i],dep[j]) print(dep[j]) p+=1 print(p) i+=1 in this condition if arr[i]<dep[j]: the value 1120 value will be stored dep[ j ] .why exactly 1120 will be stored in this condition.
– Brahma Reddy
Mar 25 at 6:41
Why you are staring i from 1 ?
– Muthu Kumar
Mar 25 at 6:45
because i don't want to start with oth index.that's why i take 1 index.
– Brahma Reddy
Mar 25 at 6:47
What exactly is your problem?
– DirtyBit
Mar 25 at 6:32
What exactly is your problem?
– DirtyBit
Mar 25 at 6:32
if arr[i]<dep[j]: print(arr[i],dep[j]) print(dep[j]) p+=1 print(p) i+=1 in this condition if arr[i]<dep[j]: the value 1120 value will be stored dep[ j ] .why exactly 1120 will be stored in this condition.
– Brahma Reddy
Mar 25 at 6:41
if arr[i]<dep[j]: print(arr[i],dep[j]) print(dep[j]) p+=1 print(p) i+=1 in this condition if arr[i]<dep[j]: the value 1120 value will be stored dep[ j ] .why exactly 1120 will be stored in this condition.
– Brahma Reddy
Mar 25 at 6:41
Why you are staring i from 1 ?
– Muthu Kumar
Mar 25 at 6:45
Why you are staring i from 1 ?
– Muthu Kumar
Mar 25 at 6:45
because i don't want to start with oth index.that's why i take 1 index.
– Brahma Reddy
Mar 25 at 6:47
because i don't want to start with oth index.that's why i take 1 index.
– Brahma Reddy
Mar 25 at 6:47
add a comment |
1 Answer
1
active
oldest
votes
Your program is little reformatted with the meaningful variable names. Hope this will answer your problem.
def bus(arr, dep, total_bus):
arr.sort()
dep.sort()
if total_bus == 0:
# when there is no bus
return 0
if dep[0] > arr[total_bus - 1]:
# when all bus comes in and after bus leaving 1 by 1
return n
platform = 1
arr_index = 1
dep_index = 0
cur_bus = 1
while arr_index < total_bus and dep_index < total_bus:
if arr[arr_index] > dep[dep_index]:
dep_index += 1
cur_bus -= 1
else:
cur_bus += 1
arr_index += 1
if cur_bus > platform:
platform += 1
return platform
arr = [900, 940, 950, 1100, 1500, 1800]
dep = [910, 1200, 1120, 1130, 1900, 2000]
n = len(arr)
print('min no.of platforms:', bus(arr, dep, n))
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55332318%2fi-have-if-condition-in-program-what-that-exact-value-be-in-that-condition%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your program is little reformatted with the meaningful variable names. Hope this will answer your problem.
def bus(arr, dep, total_bus):
arr.sort()
dep.sort()
if total_bus == 0:
# when there is no bus
return 0
if dep[0] > arr[total_bus - 1]:
# when all bus comes in and after bus leaving 1 by 1
return n
platform = 1
arr_index = 1
dep_index = 0
cur_bus = 1
while arr_index < total_bus and dep_index < total_bus:
if arr[arr_index] > dep[dep_index]:
dep_index += 1
cur_bus -= 1
else:
cur_bus += 1
arr_index += 1
if cur_bus > platform:
platform += 1
return platform
arr = [900, 940, 950, 1100, 1500, 1800]
dep = [910, 1200, 1120, 1130, 1900, 2000]
n = len(arr)
print('min no.of platforms:', bus(arr, dep, n))
add a comment |
Your program is little reformatted with the meaningful variable names. Hope this will answer your problem.
def bus(arr, dep, total_bus):
arr.sort()
dep.sort()
if total_bus == 0:
# when there is no bus
return 0
if dep[0] > arr[total_bus - 1]:
# when all bus comes in and after bus leaving 1 by 1
return n
platform = 1
arr_index = 1
dep_index = 0
cur_bus = 1
while arr_index < total_bus and dep_index < total_bus:
if arr[arr_index] > dep[dep_index]:
dep_index += 1
cur_bus -= 1
else:
cur_bus += 1
arr_index += 1
if cur_bus > platform:
platform += 1
return platform
arr = [900, 940, 950, 1100, 1500, 1800]
dep = [910, 1200, 1120, 1130, 1900, 2000]
n = len(arr)
print('min no.of platforms:', bus(arr, dep, n))
add a comment |
Your program is little reformatted with the meaningful variable names. Hope this will answer your problem.
def bus(arr, dep, total_bus):
arr.sort()
dep.sort()
if total_bus == 0:
# when there is no bus
return 0
if dep[0] > arr[total_bus - 1]:
# when all bus comes in and after bus leaving 1 by 1
return n
platform = 1
arr_index = 1
dep_index = 0
cur_bus = 1
while arr_index < total_bus and dep_index < total_bus:
if arr[arr_index] > dep[dep_index]:
dep_index += 1
cur_bus -= 1
else:
cur_bus += 1
arr_index += 1
if cur_bus > platform:
platform += 1
return platform
arr = [900, 940, 950, 1100, 1500, 1800]
dep = [910, 1200, 1120, 1130, 1900, 2000]
n = len(arr)
print('min no.of platforms:', bus(arr, dep, n))
Your program is little reformatted with the meaningful variable names. Hope this will answer your problem.
def bus(arr, dep, total_bus):
arr.sort()
dep.sort()
if total_bus == 0:
# when there is no bus
return 0
if dep[0] > arr[total_bus - 1]:
# when all bus comes in and after bus leaving 1 by 1
return n
platform = 1
arr_index = 1
dep_index = 0
cur_bus = 1
while arr_index < total_bus and dep_index < total_bus:
if arr[arr_index] > dep[dep_index]:
dep_index += 1
cur_bus -= 1
else:
cur_bus += 1
arr_index += 1
if cur_bus > platform:
platform += 1
return platform
arr = [900, 940, 950, 1100, 1500, 1800]
dep = [910, 1200, 1120, 1130, 1900, 2000]
n = len(arr)
print('min no.of platforms:', bus(arr, dep, n))
answered Mar 25 at 7:24
Muthu KumarMuthu Kumar
336212
336212
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55332318%2fi-have-if-condition-in-program-what-that-exact-value-be-in-that-condition%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What exactly is your problem?
– DirtyBit
Mar 25 at 6:32
if arr[i]<dep[j]: print(arr[i],dep[j]) print(dep[j]) p+=1 print(p) i+=1 in this condition if arr[i]<dep[j]: the value 1120 value will be stored dep[ j ] .why exactly 1120 will be stored in this condition.
– Brahma Reddy
Mar 25 at 6:41
Why you are staring i from 1 ?
– Muthu Kumar
Mar 25 at 6:45
because i don't want to start with oth index.that's why i take 1 index.
– Brahma Reddy
Mar 25 at 6:47