我是Python的新手,我想在3次之后调整我的while循环停止,请帮助!
a = "It's time. "
b = "Alarm rings!!! "
c = "Are you ready to get up ? "
print a + b + c
answer = raw_input("Enter Yes or No: ")
if answer =='Yes':
print "Climb Out of Bed"
while answer == 'No':
print a + b + c
answer = raw_input("Enter Yes or No: ")
答案 0 :(得分:1)
使用计数器跟踪您循环的次数。
a = "It's time. "
b = "Alarm rings!!! "
c = "Are you ready to get up ? "
counter = 0
print a + b + c
answer = raw_input("Enter Yes or No: ")
if answer =='Yes':
print "Climb Out of Bed"
while answer == 'No' and counter < 3:
print a + b + c
answer = raw_input("Enter Yes or No: ")
counter += 1
答案 1 :(得分:0)
尝试使用for循环来修复重复:
for i in range(3):
if answer == 'No':
print a + b + c
answer = raw_input("Enter Yes or No: ")