Jump to content
 
 
Hello forums,
I'm in need of Python help, this is my code at the moment. 
 
temp = int(input("Temperature:"))
while "42" not in temp:
  temp  = input("Temperature:")
  if temp == 42:
  print("Just right!")
elif temp > 42: 
  print("Too hot!")
elif temp < 42:
  print("Too cold!")
  
 
It mostly does what it has to do without the "while" but the question is asking to repeat "Temperature" if the temperature is either too cold or too hot and the code stops if the temperature is 42. 
Here is the example.
 
Temperature: 12
Too cold!
Temperature: 36
Too cold!
Temperature: 39
Too cold!
Temperature: 46
Too hot!
Temperature: 51
Too hot!
Temperature: 43
Too hot!
Temperature: 42
Just right!
 
 
Thanks for all the help!
 

 

|CPU: Intel 5960X|MOBO:Rampage V Extreme|GPU:EVGA 980Ti SC 2 - Way SLI|RAM:G-Skill 32GB|CASE:900D|PSU:CorsairAX1200i|DISPLAY :Dell U2412M X3|SSD Intel 750 400GB, 2X Samsung 850 Pro|

Peripherals : | MOUSE : Logitech G602 | KEYBOARD: K70 RGB (Cherry MX Brown) | NAS: Synology DS1515+  - WD RED 3TB X 5|ROUTER: AC68U

Sound : | HEADPHONES: Sennheiser HD800 SPEAKERS: B&W CM9 (Front floorstanding) ,  B&W CM Center 2 (Centre) | AV RECEIVER : Denon 3806 | MY X99 BUILD LOG!

 

Link to comment
https://linustechtips.com/topic/204295-python-help/
Share on other sites

Link to post
Share on other sites

Did you try to run it?  What error or result you got?

This is the error:

Traceback (most recent call last):

  File "program.py", line 3, in <module>
    while "42" not in temp:
TypeError: argument of type 'int' is not iterable

|CPU: Intel 5960X|MOBO:Rampage V Extreme|GPU:EVGA 980Ti SC 2 - Way SLI|RAM:G-Skill 32GB|CASE:900D|PSU:CorsairAX1200i|DISPLAY :Dell U2412M X3|SSD Intel 750 400GB, 2X Samsung 850 Pro|

Peripherals : | MOUSE : Logitech G602 | KEYBOARD: K70 RGB (Cherry MX Brown) | NAS: Synology DS1515+  - WD RED 3TB X 5|ROUTER: AC68U

Sound : | HEADPHONES: Sennheiser HD800 SPEAKERS: B&W CM9 (Front floorstanding) ,  B&W CM Center 2 (Centre) | AV RECEIVER : Denon 3806 | MY X99 BUILD LOG!

 

Link to comment
https://linustechtips.com/topic/204295-python-help/#findComment-2774287
Share on other sites

Link to post
Share on other sites

 

This is the error:

Traceback (most recent call last):

  File "program.py", line 3, in <module>
    while "42" not in temp:
TypeError: argument of type 'int' is not iterable

 

Well, google is your friend. You have to understand errors first.

So just google error last line and figure it out.

 

Why are you searching 42 in temp. Temp is not a list of numbers. Temp IS a number, an integrer. Its the input temperature number.

Link to comment
https://linustechtips.com/topic/204295-python-help/#findComment-2774320
Share on other sites

Link to post
Share on other sites

Just run a condition to check if temp is = 42 if it is print something. If you want to to keep looping till it hits 42 run a while true statement and if it hits 42 break it. I'm basing this off how I do it in c++ so it might be different in python

Also it its probably getting mad because it looks like your searching for 42 that would be in something like a array and since its just a plain integer it gets mad

CPU: i7 4770k@4.3Ghz GPU: GTX 780ti Motherboard: ROG maximus vi formula PSU: Evga supernova 1000w Platinum

Case: NZXT Switch 810 Memory: g.skill ripjaws X Cooler: Corsair h100i(getting custom loop when i get money next) Storage: Samsung 840 evo 250gb Keyboard: Corsair K95 Mouse: SteelSeries Rival

Link to comment
https://linustechtips.com/topic/204295-python-help/#findComment-2782344
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×