Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Output of Python code
#5
(Sep-13-2019, 10:57 AM)hemal07yc Wrote: I Didn't get any output
According to me, answer should be "No Output"

Kindly confirm that it is correct or not.

Thanking you in advance..

Okay, that's better...

Nevertheless, there must be an indentation (four spaces) for print, otherwise it produces an
Error:
expected an indented block error
The correct code should be:
x = "abcdef"
i = "i"
while i in x:
    print(i, end=" ")
And if you run it, nothing happens because:
1. If there were an 'i' in the string "x" ('abcdef'), then "i" would be printed. As it is not the case, nothing is printed. That explains the whole exercise, as nothing is printed; therefore the solution is number 4. No Output.

All the best,

(Sep-13-2019, 11:09 AM)perfringo Wrote:
(Sep-13-2019, 10:57 AM)hemal07yc Wrote: I Didn't get any output

So you have an answer.

However, if you are wondering why there is no output: there is no letter 'i' in x ('abcdef') so while loop is never executed as condition is false.

If you are adventurous you can write i = 'a' and observe what will happen (warning: you will enter endless loop, to break it press ctrl + c)

Oops! It seems that I posted just after you! Sorry! Blush
newbieAuggie2019

"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
Reply


Messages In This Thread
Output of Python code - by hemal07yc - Sep-13-2019, 10:44 AM
RE: Output of Python code - by newbieAuggie2019 - Sep-13-2019, 10:53 AM
RE: Output of Python code - by hemal07yc - Sep-13-2019, 10:57 AM
RE: Output of Python code - by perfringo - Sep-13-2019, 11:09 AM
RE: Output of Python code - by newbieAuggie2019 - Sep-13-2019, 11:10 AM
RE: Output of Python code - by perfringo - Sep-13-2019, 11:33 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in output of a snippet code akbarza 2 440 Feb-28-2024, 07:15 PM
Last Post: deanhystad
  Compiles Python code with no error but giving out no output - what's wrong with it? pythonflea 6 1,686 Mar-27-2023, 07:38 AM
Last Post: buran
  I cannot able to see output of this code ted 1 802 Feb-22-2023, 09:43 PM
Last Post: deanhystad
  Python VS Code: using print command twice but not getting output from terminal kdx264 4 1,197 Jan-16-2023, 07:38 PM
Last Post: Skaperen
  why I dont get any output from this code William369 2 1,187 Jun-23-2022, 09:18 PM
Last Post: William369
  How can I organize my code according to output that I want ilknurg 1 1,217 Mar-11-2022, 09:24 AM
Last Post: perfringo
  Why this code not getting desired output ? MDRI 2 2,604 Sep-18-2020, 02:11 AM
Last Post: MDRI
  I couldn't understand the output of the below code ravich129 1 1,973 Dec-12-2019, 06:24 AM
Last Post: sandeep_ganga
  Output not following rules set in code. Escribblings 4 3,167 Apr-24-2019, 12:49 PM
Last Post: Escribblings
  What will the following code output? dukoolsharma 5 3,355 Dec-15-2018, 06:05 AM
Last Post: HarshaliPatel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020