#๐ Program stopping prematurely
39 messages ยท Page 1 of 1 (latest)
@tacit geyser
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
num = int(input("Please type in a number:"))
a = 1
b = 1
while a != num and b != num:
print(f"{a} x {b} = {a*b}")
while b != num:
b += 1
print(f"{a} x {b} = {a*b}")
b = 1
a += 1```
im not sure why the program is stopping already
the while conditions havent been met yet
a is == num but b isnt yet
isnt the program supposed to keep running til both are == num
Please type in a number:4
1 x 1 = 1
1 x 2 = 2
1 x 3 = 3
1 x 4 = 4
2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
3 x 4 = 12
my code output
The screenshot here is an example?
its my code inside a python viewer tool thingy
See the examples below for details:
Can you share the examples its referring to?
ah ok that makes sense now
I would use for loops and range to accomplish this instead. Would make the program a lot simpler and easier to understand. And it would fix the issue you're having as well.
those concepts havent been introduced in this part of the course yet so I was hoping to do it with a while loop
Ah okay.
maybe while a < num ... ?
theres a lot of problems in this course that would be a lot easier with range and stuff ๐ญ but I figured it felt a bit like cheating
I'll try that thank you!
They challenge you to do that on purpose
Yeah I figured
i get the same output weirdly enough
a < num + 1 and b < num + 1 ?
Changing the outer while to while not a > num: worked for me
they worked tysm guys!
I need help in understanding why my code didnt work though
I still dont get why the program seemed to stop before the conditions were met
well think about it
if while a < num means while 4 < 4 it would stop before 4
not on 4
or in PeachTeaEnjoyer's case
while not a > num is equivalently read as while not 4 greater than 4
which is True
until it goes while not 5 greater than 4, thats False and stops there
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.