#🔒 lists and while loops

47 messages · Page 1 of 1 (latest)

stone grotto
#

Hello I have been having trouble with lists and while loops and can’t find a way to fix my code ai and YouTube were no help I have to hand this in for tomorrow so if any one has some tips on how I could fix this that would be awesome. I also am not allowed to use while true in the code

fair dustBOT
#

@stone grotto

Python help channel opened

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.

trim phoenix
fair dustBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

trim phoenix
#

Reading a code screenshot is not good for the eyes

trim phoenix
trim phoenix
stone grotto
#

I don’t know if I did that right but that’s my code

trim phoenix
fair dustBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

trim phoenix
stone grotto
#

Yes just not while true for some reason

trim phoenix
#

are you allowed to use while or not?

stone grotto
trim phoenix
#

yup

#

I get that

#

thanks for the explanation

#

its appreciated

stone grotto
trim phoenix
#

ok...

trim phoenix
stone grotto
trim phoenix
#

If its not an int, it throws a ValueError exception

solar gulch
#

Use a flag variable

flag = False
while not flag:
    inp = input()
    if inp.isditgit() and inp < min_number:
        flag = True
solar gulch
#

The switch the flag to True

#

And mark it False if the input met req

trim phoenix
#

thats such a roundabout way of doing this. Could just leave it as while True and when the if conditions are met, use break

solar gulch
#

Point is, put the input() into the while loop and set it to run the first time

#

You put the input() line outside of the loop so it will not print the prompt for the user again because it is dead lock

#

It keep checking if input is ditgit and bigger than min number but user never have a chance to type it because there's no prompt to because the prompt is outside the loop

stone grotto
#

Where would I put the except value error for str then?

trim phoenix
#
try:
  int(input())
except ValueError:
  continue
stone grotto
#

Ok that all works but now it’s giving me an error that says. < not supported between an str and a int

trim phoenix
#

That would be a different exception

#
-except ValueError:
+except (ValueError, TypeError):
stone grotto
#

Where do I put that in the try part?

trim phoenix
stone grotto
#

No I don’t think I’ve learnt that yet

trim phoenix
#

then you can skip try/except ig

#

Do what ThanhZ suggested

stone grotto
#

Ok thanks

fair dustBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, 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.