-1

If the temperature is 100 or above, the functions return “It is hot.”;

If the temperature is between 70 and 100, the function returns “It is warm.”;

If the temperature is between 32 and 70, the functions return “It is cool.”;

If the temperature is below 32, it returns “It is cold.”

The function feelTemp will take one value for the temperature, and then returns a category as a string.

When running the program, the user is prompted to input a temperature, then the program print one of the four categorical levels (hot, warm, cool, and cold) that the given temperature falls into.

I have tried this but getting an error in syntax.

What should I do?:

def feelTemp(t):
    if t<=100:
        return "It is hot."
    elif t>=70 and t<=100:
        return "It is warm."
    elif t>=32 and t<=70:
        return "It is cool."
    else:
        return "It is cold."
feelTemp(105)

And how to set an input field as well?

Nikos Tavoularis
  • 2,843
  • 1
  • 30
  • 27
Hidu
  • 19
  • 2
  • 3
    What is the error? – jmunsch Jan 31 '20 at 19:12
  • I believe you are using the incorrect conditional operators. There's overlap between `t<=100` and `t>=70 and t<=100`. You likely want to change the first conditional to `t>=100`. –  Jan 31 '20 at 19:20
  • You've fixed the syntax error in the code you originally supplied, I believe the original syntax error was that you were supplying a conditional to the else statement like `else t < 32`. – jmunsch Jan 31 '20 at 19:21
  • For your other question see: https://stackoverflow.com/questions/70797/user-input-and-command-line-arguments – jmunsch Jan 31 '20 at 19:23
  • I corrected the problem. Now, how to use input function in here? I tried: input('Enter the temperature: ') print(feelTemp) I can have the input prompt for the temperature, but when I put some values, it gives me: – Hidu Jan 31 '20 at 19:26
  • @Hidu You would need to save the user input to a variable then input that variable into the function call. You would need to print the function that has been given a value. Something like `print(feelTemp(userInput))` –  Jan 31 '20 at 19:31
  • Just use input() in python https://www.w3schools.com/python/ref_func_input.asp – MrPickles7 Jan 31 '20 at 22:15
  • Welcome, please read posts in the [Help section](http://StackOverflow.com/help) on asking questions. Particularly the part about posting exact error messages exact output, exact results, and how they differ; and sticking to a single question (with definable answers) per post (you can open a new past for additional questions). Also the sections on minimal reproducible examples, and how to ask homework questions may come in handy. According to SO guidelines, this question is subject to closure. Please `edit` accordingly to fix this issue. – SherylHohman Jan 31 '20 at 23:07

2 Answers2

1

I changed the first less than or equal sign to greater than or equal to, where it's supposed to output "It is hot."

def feelTemp():
  t = int(input("Current Temperature: "))
if t >= 100:
    print("It is hot.")
elif t>=70 and t<=100:
    print("It is warm.")
elif t>=32 and t<=70:
    print("It is cool.")
elif t >= 32:
    print("It is cold.")

feelTemp()
Nathan
  • 1,303
  • 12
  • 26
0
#include<stdio.h>
     void temp(int degree);
       int main(){
            int degree;
            printf("Enter Temperature");
            scanf("%d", &degree);
              temp(degree);

        return 0;

}

 void temp(int degree){
       if(degree>100){
           printf("Temp is hot");
          }
       if(degree<=100){
           printf("Temp is cold");
       }
   }
            
    
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 04 '22 at 00:22