What am i doing wrong?!

I tried to build this little fun project on my own and while the formulars are worning fine, i simply dont know how to make it work, maybe because i havent been working with functions for a longer time now.
I also tried different versions of this… one where i put celsius() and fahrenheit() on top and call them with for example cels= celsisus(), i still run into errors and im lost so im now asking for help.

def calculator(): print("Welcome to the NA/EU temperature converter project") ques = input(""" What do you want to convert?\n > Fahrenheit to Celsius -> Press 1. > Celsius to Fahrenheit -> Press 2. > """) if ques == 1: return celsius() if ques == 2: return fahrenheit() else: print("You didn't enter the right thing.") def celsius(): fahrenheit = int(input("Enter Fahrenheit: ")) print("Celsius >") print((fahrenheit - 32) * 5 / 9) def fahrenheit(): celsius = int(input("Enter Celsius: ")) print("Fahrenheit >") print((celsius * 9 / 5) + 32) celsius() fahrenheit() calculator()

One suspects that user input is not supported in codebytes. Code works fine a the shell.

hi, thank you for the reply.
its not running fine for me.

i wanted the menu where the user selects 1 or 2 to run first, if i execute it in PyCharm or VSCode it says “Enter Fahrenheit” instantly.

At the bottom, comment out the first two calls and keep only the one to the calculator. Also, rather than force the user to raise a KeyboardInterrupt, add a third option to quit or exit which terminates by whatever means necessary.


celsius and fahrenheit are helper functions; do you really want to leave the printing to them? Why not return a value (string or float) and print it at the caller?

return f"Fahrenheit > {celsius * 9 / 5 + 32}"
print (calculator())

Also,

if ques == 1

Recall that input() has a str return.

if ques == "1"
1 Like

This is a rebake of your code model in my local shell,

# mkcode1337
# https://discuss.codecademy.com/t/what-am-i-doing-wrong/678237

def calculator():
    print("Welcome to the NA/EU temperature converter project")
    ques = input("""
What do you want to convert?\n
> Fahrenheit to Celsius -> Enter 1.
> Celsius to Fahrenheit -> Enter 2. 
>                Escape -> Enter 0. 
> """)
    if ques == "0":
        return "Bye!"
    if ques == "1":
        return celsius()
    if ques == "2":
        return fahrenheit()
    return "You didn't enter the right thing.")

def celsius():
    fahrenheit = int(input("Enter Fahrenheit: "))
    return f"Celsius > {(fahrenheit - 32) * 5 / 9}"

def fahrenheit():
    celsius = int(input("Enter Celsius: "))
    return f"Fahrenheit > {celsius * 9 / 5 + 32}"
>>> calculator()
Welcome to the NA/EU temperature converter project

What do you want to convert?

> Fahrenheit to Celsius -> Press 1.
> Celsius to Fahrenheit -> Press 2. 
> 0
'Bye!'
>>>

hey, before i read your answer, i solved it now this way:

def calculator(): print("Welcome to the NA/EU temperature converter project") def celsius(): fahrenheit = int(input("Enter Fahrenheit: ")) print("Celsius >") print(round((fahrenheit - 32) * 5 / 9)) def fahrenheit(): celsius = int(input("Enter Celsius: ")) print("Fahrenheit >") print(round((celsius * 9 / 5) + 32)) ques = 0 while True: try: ques = int(input(""" What do you want to convert?\n > Fahrenheit to Celsius -> Press 1. > Celsius to Fahrenheit -> Press 2. > """)) except ValueError: print("You didn't enter a number") if ques == 1: celsius() break elif ques == 2: fahrenheit() break calculator()

Is that a lot better?

Thanks for the advice, will try to integrate that!

1 Like

if i run this code in my shell it works until i try to calculate anything, then it just does nothing.

image

From what one can tell, line 23 should be at around line 33, not above the conditionals.