2024-06-02 23:42:49 发布
网友
我想做一个节拍器。我的代码是:
import time import sound metronome = raw_input("") int(metronome) while 1==1: sound.play_effect('Drums_02') time.sleep(metronome)
当我运行这段代码时,它会出现一条错误消息,说“需要一个float” 如果有人能理解的话,我很伤心。你知道吗
int(metronome)不将metronome转换为整数。它创建一个新的int,然后丢弃它,因为您不使用它。你想把它传给你的sleep电话:
int(metronome)
metronome
int
sleep
time.sleep(int(metronome))
或者,如果您在多个位置使用它,请在第一位指定metronome一个int值:
metronome = int(raw_input(""))
metronome仍然是字符串,而不是整数。将int()的结果存储回变量:
int()
metronome = int(mentronome)
除了打印字符串的int表示之外,对变量不做任何操作。你知道吗
你想说:
metronome = int(metronome)
或者
int(metronome)
不将metronome
转换为整数。它创建一个新的int
,然后丢弃它,因为您不使用它。你想把它传给你的sleep
电话:或者,如果您在多个位置使用它,请在第一位指定
metronome
一个int
值:metronome
仍然是字符串,而不是整数。将int()
的结果存储回变量:除了打印字符串的int表示之外,对变量不做任何操作。你知道吗
你想说:
或者
相关问题 更多 >
编程相关推荐