Python - input problem

hello, first time here, im trying to get my code to read a number and check if you can divide it with 3 and 5 and so on but i cant get it to use the defined input in the first place. im really confused and stuck right now… hope somebody can help me

def fizzbuzz_lib():

fizzbuzz = input("ganze Zahl n: ")

if fizzbuzz % 3 == 0 and fizzbuzz % 5 == 0:
    return'FizzBuzz!'
else: 

    if fizzbuzz % 3 == 0 and not fizzbuzz % 5 == 0:
        return'Fizz!'
    
    else:
        if fizzbuzz % 5 == 0 and not fizzbuzz % 3 == 0:
            return'Buzz!'

        else:
            return fizzbuzz

Hey there!! Welcome to the forums :slightly_smiling_face:

Is this all of your code? Currently you have several returns outside of a function.


As for your input() problem I am guessing it is due to the lesson you are on. Are you getting an End Of File or EOF Error? If so it is most likely because of the way the Codecademy consoles are built. The majority of them are not capable of reading input from the console, so when the input() runs and can’t collect anything it throws an EOF Error.

hello :slight_smile: yes this is all the code, played around with return/print and forgot to write back for now…
my issue is that im not getting a response in the shell at all, its just blank, im using
the online compiler from https://www.programiz.com/python-programming/online-compiler/ currently

def fizzbuzz_lib():

fizzbuzz = float(input("ganze Zahl n: "))

if fizzbuzz % 3 == 0 and fizzbuzz % 5 == 0:
    print('FizzBuzz!')
else: 

    if fizzbuzz % 3 == 0 and not fizzbuzz % 5 == 0:
        print('Fizz!')

    else:
        if fizzbuzz % 5 == 0 and not fizzbuzz % 3 == 0:
            print('Buzz!')

        else:
            print(fizzbuzz)
                return

if i write my code as its block without “def fizzbuzz_lib():” the first part, it seems to work, i thought def would just name it, but it does more then that…

When putting your code in the function block, did you call it? The code inside a function will not run unless called:

def function():
  return 'Hello World!'

print(function())
>>> 'Hello World!'

Also, I feel like your code is really redundant.

This code (among others) can be easily rewritten as

elif fizzbuzz % 3 == 0 and not fizzbuzz % 5 == 0:
   print('Fizz!')
2 Likes

i see, i did not. ok that solves a lot for now, thanks you very much :slight_smile:

1 Like