J
J
Junior2020-04-27 23:06:26
Python
Junior, 2020-04-27 23:06:26

Why doesn't the Python code work?

Here is the code:

def calculate():
    n = input("Кол-во учеников: ")
    k = input("Кол-во яблок: ")
    print("Кол-во яблок что получил кадлый ученик: "+k//n+"\n Кол-во яблок осталось: "+k%n)
    
calculate();


Conclusion:
Кол-во учеников: Кол-во яблок: 

Traceback (most recent call last):
  File "./Playground/file0.py", line 6, in <module>
    calculate();
  File "./Playground/file0.py", line 3, in calculate
    k = input("Кол-во яблок: ")
EOFError: EOF when reading a line


What could be wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Karbivnichy, 2020-04-27
@IT-Programmer

Because do not divide a number by a number, but a line by a line.
n = int(input("Number of students: ")) - you need to convert the string to a number.
So a little prettier:

def calculate():
  
    n = int(input("Кол-во учеников: "))
    k = int(input("Кол-во яблок: "))

    print(f'Кол-во яблок что получил кадлый ученик: {k//n}')
    print(f'Кол-во яблок осталось: {k%n}')
    
calculate();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question