[英]raw_input_wrapper() takes from 0 to 1 positional arguments but 2 were given Python 3.5
[英]TypeError: raw_input() takes from 1 to 2 positional arguments but 4 were given
所以我是 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
我不知道是什么問題。 期待幫助。
input
不像print
; 它不會將其參數連接成單個字符串。 您需要自己執行此操作,例如使用 f 字符串。
x = int(input(f'Which season of {x} do you want to play?')
input
只接受一個參數。 你在線上傳遞了三個:
y = int(input('Which season of',x,'you want to play?'))
請參閱https://docs.python.org/3/library/functions.html#input
您可能想嘗試使用 f-strings。 https://www.python.org/dev/peps/pep-0498/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.