@[TOC]我的python学习笔记-超简单的小程序
猜数字
1.允许用户最多尝试三次
2.每尝试三次后,如果还没猜对,询问用户是否还想继续玩,回答Y或者y, 用户可以继续玩三次
3.如果才对了,退出游戏。
import random
n = random.randint(0,10)
count = 0
while count < 100:
user_guess=int(input("请输入你猜的数字:"))
if user_guess > n :
print("----try smaller----")
elif user_guess < n :
print("----try larger----")
else :
print("----bingo----")
break
if count == 2 :
question = input("你还想继续玩吗?")
if question != "n" or "N" :
count = 0
else :
print("欢迎下次再来!")
break
count +=1
成绩分组输出
输入一个分数。分数在 0-100 之间。90 以上是 A,80 以上是 B,70 以上是 C,60 以上是 D。60 以下是 E。
score = int(input("请输入一个在 0-100 之间的数字:"))
grade = ""
if score>100 or score<0:
score = int(input("输入错误!请重新输入一个在 0-100 之间的数字:"))
else:
if score >= 90: grade = "A"
elif score >= 80: grade = 'B'
elif score >= 70: grade = 'C'
elif score >= 60: grade = 'D'
else:grade = 'E'
print("分数为{0},等级为{1}".format(score,grade))
双色球彩票选购程序
1.先让用户依次选择6个红球,在选择2个蓝色球,最后统一打印选取的编号。
2. 确保用户不能重复选择,也不能超出范围。红球1-33 蓝球1-16
red_ball = []
blue_ball = []
count = 0
count_red = 0
count_blue = 0
while count_red < 6 :
red_bar = input("Select red ball:").strip()
if red_bar.isdigit() :
red_bar = int(red_bar)
if red_bar in red_ball :
print("number",red_bar,"is already exist in red ball list.")
elif red_bar > 0 and red_bar < 33 :
red_ball.append(red_bar)
count_red += 1
print("This is your",count_red,"select your red ball:",red_ball)
elif red_bar < 0 or red_bar > 33 :
print("Your only can select number 1-32 of red ball.")
question = input("Do you parpare for choosing your blue ball?")
if question == "Y" or "y":
while count_blue < 2:
blue_bar = input("Select blue ball:").strip()
if blue_bar.isdigit():
blue_bar = int(blue_bar)
if blue_bar in blue_ball:
print("number", blue_bar, "is already exist in blue ball list.")
elif blue_bar > 0 and blue_bar < 16:
blue_ball.append(blue_bar)
count_blue += 1
print("This is your", count_blue, "select your blue ball:", blue_ball)
elif blue_bar < 0 or red_bar > 16:
print("Your only can select number 1-16 of blue ball.")