Python中想调用获得的数字该怎么做

id=2.0
x= int(id)
os.system(‘mplayer %s' % music_x)
具体问题类似上面,我想调用我之前程序运行得到的2,把它赋予到music_x中的x,以达到最终播放music_2的效果。
现在的问题是music_x没有变成music_2,所以一直播放不出来

music改成一个列表吧,通过参数访问

可以通过拼接歌曲名称的字符串,再播放这个指定名称的歌曲就可以了,下面代码在Windows系统下测试。

修改如下:

参考链接:


https://www.coder.work/article/5028846


import os
id=2.0  # 小数数字后缀
x= int(id)  # 将小数转为整数类型
#songPath="f:\\"
songName="music_"+str(x)  # 把数字拼接到字符串"music_"后面,形成要播放歌曲的名称
#print(songName)
#print('mplayer %s' % songName)
# 播放 指定名字的曲
# https://mplayerwin.sourceforge.net/downloads.html
# https://www.coder.work/article/5028846
os.system('mplayer %s' % (songName))


img