小编Gil*_*ani的帖子

在Python中嵌套While循环

我是python编程的初学者.我编写了以下程序,但它没有像我想要的那样执行.这是代码:

b=0
x=0
while b<=10:
    print 'here is the outer loop\n',b,
    while x<=15:
        k=p[x]
        print'here is the inner loop\n',x,
        x=x+1
    b=b+1
Run Code Online (Sandbox Code Playgroud)

有人能帮帮我吗?我将非常感激!此致,吉拉尼

python while-loop

2
推荐指数
2
解决办法
5万
查看次数

使用python脚本删除文件

我想用python脚本删除一些文件(使用Windows时).我试过以下代码:

>>>import os
>>> os.remove ('D:\new.docx')
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误:

Traceback (most recent call last):

  File "<pyshell#1>", line 1, in -toplevel-

    os.remove ('D:\new.docx')
OSError: [Errno 22] Invalid argument: 'D:\new.docx'
Run Code Online (Sandbox Code Playgroud)

这里的任何人都可以帮我吗?

谢谢.

吉拉尼

python file

2
推荐指数
2
解决办法
537
查看次数

嵌套for循环中的错误(Python)

我在以下代码中收到错误.错误消息是"Error: Inconsistent indentation detected!"

s=[30,40,50]
a=[5e6,6e6,7e6,8e6,8.5e6,9e6,10e6,12e6]
p=[0.0,0.002,0.004,0.006,0.008,0.01,0.015,0.05,0.1,0.15,0.2]
j=0
b=0
x=0


for j in s:
    h=s[j]
    print "here is the first loop" +h
    for b in a:
           c=a[b]                                #too much indentation
           print"here is the second loop" +c     #too much indentation
           for x in p:                           #too much indentation
                k=p[x]
                print"here is the third loop" +k
Run Code Online (Sandbox Code Playgroud)

如果有任何其他错误,如果有人在这里纠正我,我将非常感激.

谢谢.

/吉拉尼

python syntax

1
推荐指数
2
解决办法
1749
查看次数

标签 统计

python ×3

file ×1

syntax ×1

while-loop ×1