如何完成一个while循环...... [英] how to finish a while loop...

查看:82
本文介绍了如何完成一个while循环......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是python的新手。学习我自己如何要求用户

完成一个循环。

出于某种原因,它表现为无限循环虽然我改变了它的

条件。请告诉我我做错了什么。在此先感谢。

条件=真


而(条件):


尝试:

integer_one = int(raw_input(" Please enter a

integer:"))

integer_two = int(raw_input(" Please enter thebr />
第二个整数:"))

division = integer_one / integer_two

除了(ZeroDivisionError):

打印\ nDivision by zero detected

除外(ValueError):

print" \ n你没有输入整数

else:

print"结果是&,'division

answer = raw_input("你想再试一次(是或否

否)?")

如果回答==''是'':

条件

elif answer ==' '不'':

条件=错误


打印再见,你不想继续

Hi all, i''m new to python. Learning on my own how to ask a user to
finish a loop or not.
For some reason, it behaves as infinite loop although I changed its
condition. Please tell me what I''m doing wrong. Thanks in advance.
condition = True

while ( condition ):

try:
integer_one = int ( raw_input( "Please enter an
integer: " ) )
integer_two = int ( raw_input( "Please enter the
second integer: " ) )
division = integer_one / integer_two

except( ZeroDivisionError ):
print "\nDivision by zero detected"
except( ValueError ):
print "\nYou didn''t enter an integer"
else:
print "The result is", division
answer = raw_input("Do you want to try again (yes or
no)? ")
if answer == ''yes'':
condition
elif answer == ''no'':
condition = False

print "Good bye, you don''t want to continue"

推荐答案

200 8/2/19,icarus< rs **** @ gmail.com>:
2008/2/19, icarus <rs****@gmail.com>:

大家好,我是python的新手。学习我自己如何要求用户

完成一个循环。

出于某种原因,它表现为无限循环虽然我改变了它的

条件。请告诉我我做错了什么。在此先感谢。


条件=真


而(条件):


尝试:

integer_one = int(raw_input(" Please enter a

integer:"))

integer_two = int(raw_input(" Please)输入

秒整数:"))

division = integer_one / integer_two


除(ZeroDivisionError):

print" \\\
Division by zero detected"

除了(ValueError):

print" \ nYouou没有输入整数

else:

print"结果是&,'division

answer = raw_input("你想再试一次(是或是

否)?")

如果回答==''是'':

条件

elif回答==''不'':

条件=错误


打印再见,你不想继续


-
http://mail.python.org/mailman/listinfo/python-list



该代码有效。也许你在发邮件时修好了它=)


-

- Guilherme H. Polo Goncalves

That code works. Maybe you fixed it while you were mailing it =)

--
-- Guilherme H. Polo Goncalves


2月20日上午9:00,icarus< rsa ... @ gmail.comwrote:
On Feb 20, 9:00 am, icarus <rsa...@gmail.comwrote:

大家好,我是新手到python。学习我自己如何要求用户

完成一个循环。

出于某种原因,它表现为无限循环虽然我改变了它的

条件。请告诉我我做错了什么。在此先感谢。


条件=真


而(条件):


尝试:

integer_one = int(raw_input(" Please enter a

integer:"))

integer_two = int(raw_input(" Please)输入

秒整数:"))

division = integer_one / integer_two


除(ZeroDivisionError):

print" \\\
Division by zero detected"

除了(ValueError):

print" \ nYouou没有输入整数

else:

print"结果是&,'division

answer = raw_input("你想再试一次(是或是

否)?")

如果回答==''是'':

条件

elif回答==''不'':

条件=错误


打印再见,你不想继续
Hi all, i''m new to python. Learning on my own how to ask a user to
finish a loop or not.
For some reason, it behaves as infinite loop although I changed its
condition. Please tell me what I''m doing wrong. Thanks in advance.

condition = True

while ( condition ):

try:
integer_one = int ( raw_input( "Please enter an
integer: " ) )
integer_two = int ( raw_input( "Please enter the
second integer: " ) )
division = integer_one / integer_two

except( ZeroDivisionError ):
print "\nDivision by zero detected"
except( ValueError ):
print "\nYou didn''t enter an integer"
else:
print "The result is", division
answer = raw_input("Do you want to try again (yes or
no)? ")
if answer == ''yes'':
condition
elif answer == ''no'':
condition = False

print "Good bye, you don''t want to continue"



条件=真


而(条件):

尝试:

integer_one = int(raw_input(" Please enter an integer:"))

integer_two = int(raw_input(" Please enter second second

整数:))

division = integer_one / integer_two

除外(ZeroDivisionError):

print" \ nDivision by zero detected"

除了(ValueError):

print" \ n你没有输入整数

else:

打印结果是,分部

答案= raw_input(你想再试一次(是或否)?

如果回答==''是'':

条件

elif回答==''不'':

condition = False

print"再见,你不想继续

试试这个。

缩进在python中非常重要。更加关心它。

你会发现python对我们来说非常好。

condition = True

while ( condition ):
try:
integer_one = int ( raw_input( "Please enter an integer: " ) )
integer_two = int ( raw_input( "Please enter the second
integer: " ) )
division = integer_one / integer_two
except( ZeroDivisionError ):
print "\nDivision by zero detected"
except( ValueError ):
print "\nYou didn''t enter an integer"
else:
print "The result is", division
answer = raw_input("Do you want to try again (yes or no)? ")
if answer == ''yes'':
condition
elif answer == ''no'':
condition = False
print "Good bye, you don''t want to continue"
Try this.
The indent is very important in python. Take more care about it.
You''ll find python is very good for us.


icarus< rs **** @ gmail.com写的:
icarus <rs****@gmail.comwrites:

出于某种原因,虽然我改变了它的

条件,但它表现为无限循环。请告诉我我做错了什么。提前致谢。
For some reason, it behaves as infinite loop although I changed its
condition. Please tell me what I''m doing wrong. Thanks in advance.



当我尝试它时它起作用:

It worked when I tried it:


>> ##处理文件中的区域/ usr / tmp / python-13922e2f ...
>>## working on region in file /usr/tmp/python-13922e2f...



请输入一个整数:8

请输入第二个整数:3

结果是2

你想再试一次(是的)或没有)?是的

请输入一个整数:8

请输入第二个整数:2

结果是4

你想再试一次(是或否)?没有

再见,你不想继续

Please enter an integer: 8
Please enter the second integer: 3
The result is 2
Do you want to try again (yes or no)? yes
Please enter an integer: 8
Please enter the second integer: 2
The result is 4
Do you want to try again (yes or no)? no
Good bye, you don''t want to continue


这篇关于如何完成一个while循环......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆