Question

In the code below,how many times "Hello" is going to be printed if the user enters...

In the code below,how many times "Hello" is going to be printed if the user enters 15 and 17 respectively? goal = int(input())

for lp in range(0,goal,3):

print("Hello")

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer: 5 & 6

5 times "Hello" will be printed if you enter 15
6 times "Hello" will be printed if you enter 17


Explanation:

As you enter 15, then for loop will be executed 5 times, as the value of lp(counter) will be increased by 3 for every iteration as mentioned

0 Hello
3 Hello
6 Hello
9 Hello
12 Hello

As the value of lp becomes 15, the control will come out from the for loop and print "Hello" 5 times.


As you enter 17, then for loop will be executed 6 times, as the value of lp(counter) will be increased by 3 for every iteration as mentioned

0 Hello
3 Hello
6 Hello
9 Hello
12 Hello
15 Hello

As the value of lp becomes 18, the control will come out from the for loop and print "Hello" 6 times.

Output:

> Windows PowerShell PS C:\Users\user\Desktop> py PrintDemo.py 15 Hello Hello Hello Hello Hello PS C:\Users\user\Desktop> Typ

Windows PowerShell PS C:\Users\user\Desktop> py PrintDemo.py 17 Hello Hello Hello Hello Hello Hello PS C:\Users\user\Desktop>

Add a comment
Know the answer?
Add Answer to:
In the code below,how many times "Hello" is going to be printed if the user enters...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT