基于python3.4
while循环
#!/usr/bin/python3
#-*- coding=utf-8 -*- import random
import sys
import os lucky_num = int(random.randint(0,9))
guess_count = 0
os.system('clear')
print("---------猜数字游戏----------")
while guess_count < 3:
input_num = int(input("请输入0~9的数字:"))
if input_num > lucky_num:
print("输入的数字大了")
elif input_num < lucky_num:
print("输入的数字小了")
else:
print("Bingo!")
break
sys.exit()
guess_count += 1 else:
print("没有机会了,请下次再来~")
for循环
#!/usr/bin/python3
#-*- coding=utf-8 -*- import random
import sys
import os lucky_num = int(random.randint(0,9))
os.system('clear')
print("---------猜数字游戏----------")
for i in range(3):
input_num = int(input("请输入0~9的数字:"))
if input_num > lucky_num:
print("输入的数字大了")
elif input_num < lucky_num:
print("输入的数字小了")
else:
print("Bingo!")
break
sys.exit() else:
print("没有机会了,请下次再来~")