0

I'm extremely new to coding so please bear with me.
I'm currently trying to make a temperature converter and I'm stuck on figuring out how to get an if function to detect if a specific variable is missing an input, essentially I want to be able to leave it empty and if it is empty I would like it to move on to the next stage of the if function.

Below is what I tried doing to figure this out but completely misunderstood what none is meant for

if fahrenheit_input!=None:
    print(celcius_answer)
elif celcius_input!=None:
    print(fahrenheit_answer)
elif fahrenheit_input==None:
    print('No Input')
elif celcius_input==None:
    print('No Input')

The end goal is the mix in the following if functions so that when I run it I'm only given 1 variable

if fahrenheit_input==32:
    print(celcius,'degrees celcius')
else:print(celcius_answer)
if celcius_input==0:
    print(fahrenheit,'degrees fahrenheit')
else:print(fahrenheit_answer)

and for a little more context I've added the code with notes on what does what

### summary of code ###

fahrenheit=32
fahrenheit_input=
celcius=0
celcius_input=
#above are the constants and human inputs

celcius_ans_1=fahrenheit_input-32
celcius_ans_2=celcius_ans_1*5
celcius_ans_3=celcius_ans_2/9
#above is the equation used to determine the fahrenheit to Celsius conversion

fahrenheit_ans_1=celcius_input*9
fahrenheit_ans_2=fahrenheit_ans_1/5
fahrenheit_ans_3=fahrenheit_ans_2+32
#above is the equation used to determine the Celsius to fahrenheit conversion(at my current level I found this to be much simpler as writing them outright would give the wrong answers)

fahrenheit_answer=fahrenheit_ans_3,'degrees farenheit'
celcius_answer=celcius_ans_3,'degrees celcius'
#up above are the answers that are going to be called

if fahrenheit_input==32:
    print(celcius,'degrees celcius')
else:print(celcius_answer)
if celcius_input==0:
    print(fahrenheit,'degrees fahrenheit')
else:print(fahrenheit_answer)
#above is the meat and potato to this as since it is meant to determine if the constant values or if the human input answers will be used

if fahrenheit_input!=None:
    print(celcius_answer)
elif celcius_input!=None:
    print(fahrenheit_answer)
elif fahrenheit_input==None:
    print('No Input')
elif celcius_input==None:
    print('No Input')
#above is my attempt to allow the human inputs to remain empty
semmyk-research
  • 333
  • 1
  • 9
  • You left off the function definition, which would show us the signature of the function, as well as an actual call to the function (i.e. the line starting with `def` and a line calling the function by its name and passing parameters). It's not entirely clear what your intent is with the `_input` parameters - why do you need 4 values? Do you want your function to do anything other than computing the converted result for some provided value, i.e. C to F, or F to C? – Grismar Mar 06 '23 at 05:45
  • I noticed you've edited your question. Thanks. NB: I've attempted editing further for readability. ... ... With your amendment, it appears you might have to consider `function` with `arg` processing and `return`, `input`, and `global` variable. I'll edit my answer to give further information. – semmyk-research Mar 06 '23 at 06:33
  • `fahrenheit_input=` is not valid Python. Please provide a proper [mre] – tripleee Mar 06 '23 at 06:35
  • A more modular design would ask for an input with a unit (maybe a number and a letter as separate inputs, or just a string which needs to contain a number and F or C) and take it from there. – tripleee Mar 06 '23 at 06:36
  • You may want to check the following: [Python 3 - Temperature Converter](https://stackoverflow.com/questions/52822650/python-3-temperature-converter) | [Python Temperature Converter](https://stackoverflow.com/questions/17014177/python-temperature-converter) | [Temperature Converter Problems](https://stackoverflow.com/questions/28978678/temperature-converter-problems) – semmyk-research Mar 06 '23 at 14:00

1 Answers1

0

Welcome to coding. Welcome to SO.

In Python, function connotes a meaning. It isn't loose English. As a starter, kindly take time to learn about function in Python.

Also learn about input()

You should put your if ... elif ...else conditional test within a function, say

def temp_converter(fahrenheit_input:float =None, celcius_input:float =None):
    #test arg1 ... 
    #test arg2 ...

    #test condition1

    #test condition2

    #convert Celsius to fahrenheit
    celsius-to_fahrenheit(celcius_input)

    #convert Fahrenheit to Celsius
    fahrenheit_to_celsius(fahrenheit_input)

    #further processing
    ... ...

    return ...

Read: How do I add default parameters to functions when using type hinting?

Consider breaking your 'codes' into smaller chunks. #Modular. See snippets below

def celsius-to_fahrenheit(celcius_input=0):
    ## process code here

    return ...
def fahrenheit_to_celsius(fahrenheit_input=32):
    ## process code here

    return ...
semmyk-research
  • 333
  • 1
  • 9