def main():
print ("This program illustrates a chaotic function")
x = (float(input("Enter a number between 0 and 1: ")))
for i in range(10):
x = 3.9 * x * (1-x)
print (x)
main()
Run Code Online (Sandbox Code Playgroud)
当我在我的 Visual Studio Code 桌面应用程序中键入上面的程序时,它返回问题通知:
W0612: Unused variable 'i'
Run Code Online (Sandbox Code Playgroud)
但是当我使用内置的 python '空闲'解释器运行相同的程序时,程序运行得很好。
在下面的代码中,有没有办法可以将for循环中的'nth'更改为我正在考虑的特定术语.
例如:输入第一个术语的值,输入第二个术语的值,输入第三个术语的值,依此类推.与每次循环运行时"输入第n项的值"行相反.
for _ in range (n):
total += float (input ('Enter a value for the nth term: '))
Run Code Online (Sandbox Code Playgroud)