小编Edw*_*ere的帖子

Break在循环python之外

while True:
    x = raw_input()
    if x =="personal information": 
         print' Edward , Height: 5,10 , EYES: brown , STATE: IL TOWN:  , SS:'
    elif x =="journal":
         name_of_file = raw_input("What is the name of the file: ")
         completeName = "C:\\python\\" + name_of_file + ".txt"
         file1 = open(completeName , "w")
         toFile = raw_input("Write what you want into the field")
         file1.write(toFile)
         file1.close()
else:
 break 
Run Code Online (Sandbox Code Playgroud)

脚本继续给我一个错误,说break是在循环之外是缩进错了吗?

python loops if-statement break

-1
推荐指数
1
解决办法
920
查看次数

我如何让我的程序转移到python中的下一个elif

import random
print"hello what is your name?"
name = raw_input()
print"hello", name
print"wanna play a game? y, n"
choice = raw_input()
if choice =='y':
    print'good lets start a number guessing game'

elif choice =='n':
    print'maybe next time'
    exit()

random.randint(1,10)
number = random.randint(1,10)
print'pick a number between 1-10'
numberofguesses = 0
guess = input()

while numberofguesses < 10:
 if guess < number:
    print"too low"
 elif guess > number:
        print"too high"
 elif guess == number:
        print'your correct the number is', number
 break …
Run Code Online (Sandbox Code Playgroud)

python if-statement

-1
推荐指数
1
解决办法
189
查看次数

我在哪里把中断放在我的代码中?

print'Personal information, journal and more to come'

while True:

    x = raw_input()
    if x =="personal information": 
         print' Edward , Height: 5,10 , EYES: brown , STATE: IL TOWN:  , SS:'
    elif x =="journal":
       print'would you like  you open a journal or create a new one? open or create'
if x =='createfile':
           name_of_file = raw_input("What is the name of the file: ")
           completeName = "C:\\python\\" + name_of_file + ".txt"
           file1 = open(completeName , "w")
           toFile = raw_input("Write what you want into …
Run Code Online (Sandbox Code Playgroud)

python loops break

-3
推荐指数
1
解决办法
130
查看次数

标签 统计

python ×3

break ×2

if-statement ×2

loops ×2