TypeError: raw_input () принимает от 1 до 2 позиционных аргументов, но было дано 4 - PullRequest
0 голосов
/ 16 января 2020

Итак, я новичок в python и сейчас изучаю функции. Поэтому я создал следующую функцию, которую я не знаю, почему она не работает.

   def open_netflix():
    print('Opening Netflix')
    x = str(input('Enter the Season you want to play:  '))
    y = int(input('Which season of',x,'you want to play?'))
    z = int(input('Which episode?'))
    print('Playing',x,y,z)

Я получаю сообщение об ошибке:

Opening Netflix
Enter the Season you want to play:  Breaking Bad
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-18-82ce4ad2e7d2> in <module>
----> 1 open_netflix()

<ipython-input-17-917a60c59ffa> in open_netflix()
      2     print('Opening Netflix')
      3     x = str(input('Enter the Season you want to play:  '))
----> 4     y = int(input('Which season of',x,'you want to play?'))
      5     z = int(input('Which episode?'))
      6     print('Playing',x,y,z)

TypeError: raw_input() takes from 1 to 2 positional arguments but 4 were given

Я не знаю, что проблема в. Ждем помощи.

Ответы [ 2 ]

2 голосов
/ 16 января 2020

input не похоже на print; он не объединяет свои аргументы в одну строку. Вы должны сделать это самостоятельно, например, используя f-строку.

x = int(input(f'Which season of {x} do you want to play?')
0 голосов
/ 16 января 2020

input принимает только один аргумент. Вы проходите три в строке:

y = int(input('Which season of',x,'you want to play?'))

Пожалуйста, смотрите https://docs.python.org/3/library/functions.html#input

Вы, вероятно, хотите попробовать f- строки. https://www.python.org/dev/peps/pep-0498/

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...