首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >TypeError: raw_input()接受1到2个位置参数,但给出了4个

TypeError: raw_input()接受1到2个位置参数,但给出了4个
EN

Stack Overflow用户
提问于 2020-01-17 00:43:02
回答 2查看 1.4K关注 0票数 0

所以我是python的新手,我现在正在学习函数。所以我创建了一个下面的函数,我不知道为什么它不能工作。

代码语言:javascript
运行
复制
   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)

我得到的错误消息是:

代码语言:javascript
运行
复制
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

我不知道问题出在哪里。期待你的帮助。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-01-17 00:48:50

input只接受一个参数。你在线路上传了三个:

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

请参阅https://docs.python.org/3/library/functions.html#input

你可能想试试f-string。https://www.python.org/dev/peps/pep-0498/

票数 0
EN

Stack Overflow用户

发布于 2020-01-17 00:46:49

inputprint不同;它不将参数连接到单个字符串中。您需要自己执行此操作,例如使用f-string。

代码语言:javascript
运行
复制
x = int(input(f'Which season of {x} do you want to play?')
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59774261

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档