37,718
社区成员
发帖
与我相关
我的任务
分享
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:Bell Sun
age_of_Sun_gf = 25
i = 0
print(type(i))
for i in range(4):
guess_age_of_Sun_gf = int(input("Please input Bell Sun's girlfriend age:"))
if age_of_Sun_gf == guess_age_of_Sun_gf:
print("Your guess is right !")
break
elif age_of_Sun_gf < guess_age_of_Sun_gf:
print("Your guess is too big !")
else:
print("Your guess is too low !")
print("i =", i)
while i == 3:
guess_continue = input("if you want to continue guess , please don't press 'n' .")
print("this")
if guess_continue != 'n':
i = 0
print("i =", i)
else:
print("See you next time !")
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:Bell Sun
age_of_Sun_gf = 25
i = 0
while i < 3:
guess_age_of_Sun_gf = int(input("Please input Bell Sun's girlfriend age:"))
if age_of_Sun_gf == guess_age_of_Sun_gf:
print("Your guess is right !")
break
elif age_of_Sun_gf < guess_age_of_Sun_gf:
print("Your guess is too big !")
else:
print("Your guess is too low !")
print("i =", i)
i += 1
if i == 3:
guess_continue = input("if you want to continue guess , please don't press 'n' .")
if guess_continue != 'n':
i = 0
else:
print("See you next time !")
外面用while循环是可以实现需求的,但是把外面的替换成for循环就会出现问题,请问有什么合适的方法吗
def func(age_of_Sun_gf):
for i in range(3):
guess_age_of_Sun_gf = int(input("Please input Bell Sun's girlfriend age:"))
if age_of_Sun_gf == guess_age_of_Sun_gf :
print("Your guess is right !")
break
elif age_of_Sun_gf < guess_age_of_Sun_gf :
print("Your guess is too big !")
else :
print("Your guess is too low !")
i += 1
if i==3:
guess_continue = input("if you want to continue guess , please don't press 'n' .")
if guess_continue != 'n' :
func(age_of_Sun_gf)
else :
print("See you next time !")
else:
return True
func(25)