#๐Ÿ”’ python while and for loops help

46 messages ยท Page 1 of 1 (latest)

nimble trout
prime orbitBOT
#

@nimble trout

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.

warm perch
nimble trout
sudden oasis
#

What do you need help with?

nimble trout
#
temp = float(input("What is the current temperature?: "))
sudden oasis
#

Looks good to me

warm perch
nimble trout
#

i was wondering if it was a good start to the question

#

the prompt above

sudden oasis
#

Yes

tired valley
#

he's on call getting help

nimble trout
#

I need to use while loops

#

but for context

#

we did not do functions

#
temp = float(input("What is the current temperature?: "))
while True:
hazy isle
#

\n

nimble trout
#

print("The temperature is too high! Turn down the vat's temperature, wait 5 minutes, and check

hazy isle
#

print("The temperature is too high! \n Turn down the vat's temperature, wait 5 minutes, and check")

tired valley
#
text
text
text
"""

print(a)```
nimble trout
hazy isle
#

print("The temperature is too high! Turn down the vat's temperature, wait 5 minutes, and check"

#

"

nimble trout
tired valley
#
World""")
nimble trout
#
while True:
    temp = float(input("What is the current temperature?: "))
    if temp <= 102.5:
        continue
    elif temp > 102.5:
        print("""The temperature is too high! Turn down the vat's temperature,
        wait 5 minutes, and then check the temperature again.""")
        temp = float(input("What is the current temperature?: ")
        if temp < 102.5:
            continue
        elif temp > 102.5:
            temp = float(input("What is the current temperature?: "))
    else:
        continue
#
while True:
    temp = float(input("What is the current temperature?: "))
    if temp <= 102.5:
        print("This temperature is alright. Check back in 15 minutes")
        continue  
    elif temp > 102.5:
        print("""The temperature is too high! Turn down the vat's temperature,
        wait 5 minutes, and then check the temperature again.""")
        temp = float(input("What is the current temperature?: ")
        if temp < 102.5:
            continue
        elif temp > 102.5:
            temp = float(input("What is the current temperature?: "))
    else:
        continue
#
while True:
    temp = float(input("What is the current temperature?: "))
    if temp <= 102.5:
        print("This temperature is alright. Check back in 15 minutes")
        continue
    elif temp > 102.5:
        print("""The temperature is too high! Turn down the vat's temperature,
        wait 5 minutes, and then check the temperature again.""")
        temp = float(input("What is the current temperature?: "))
        if temp < 102.5:
            continue
        elif temp > 102.5:
            temp = float(input("What is the current temperature?: "))
    else:
        continue
#
while True:
    temp = float(input("What is the current temperature?: "))
    if temp <= 102.5:
        print("This temperature is alright. Check back in 15 minutes")
        continue
    elif temp > 102.5:
        print("""The temperature is too high! Turn down the vat's temperature,
        wait 5 minutes, and then check the temperature again.""")
        temp = float(input("What is the current temperature?: "))
        if temp <= 102.5:
            continue
        elif temp > 102.5:
            temp = float(input("What is the current temperature?: "))
    else:
        continue
toxic anchor
#

Then use time.sleep()

#

I forget if its in seconds or milliseconds

#

be sure to import time at the top

toxic anchor
hybrid wave
#

time.sleep() is seconds. Same as time.time() returns. It accepts floats, so you can sleep for less than a second if required.

nimble trout
#

No import, no function

hybrid wave
#

There's an unbounded amount of things you won't yet have done. Same for us.

#

But if you can't use this for the class, just assume the user using your script will just wait themselves, and only enter a new value at the input() when they're ready.

toxic anchor
prime orbitBOT
#
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.