python - TypeError: raw_input() 接受 1 到 2 个位置参数,但给出了 4 个
问题描述
所以我是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?')
推荐阅读
- python - 如何解决我的点击并不总是准确的问题
- sql-server - 如何在 Azure Data Studio 中折叠所有区域
- mysql - 如果新值不为空,如何更新行字段
- shopify - Shopify - 将文件 CSV 订购到文本文件
- c++ - 解码霍夫曼树 C++
- netsuite - Suitelets 何时触发用户事件脚本?
- amazon-web-services - 将用户限制在一个区域 AWS
- python - 如何在过滤条件pyspark中使用函数
- ios - 使用 AVAudioRecorder 录制后,AVAudioPlayer 不通过扬声器播放
- python - 等待函数,直到它在 python 异步 IO 中收到回调