我的python学习笔记-猜数字/双色球/成绩统计/回答问题最多三次

@[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.")

在这里插入图片描述

回答问题最多三次

一共有三次答题机会,如果账号为one,密码为123,输出登陆成功,如果回答错误并且输入超过三次,输出“回答太多次了!”

count = 0
while True:
    if count == 4:
        print("Too many times!")
        break
    name = input("Please input your name:").strip()
    password = input("Please input your password:").strip()
    count += 1
    if name or password:
        if name == "one" and password == "123":
            print("Login successfully!")
            exit()
        else:
            print("Login failed,you have only",(3-count),"times")
    else:
        print("Please enter your name and password before landing ")
        continue

在这里插入图片描述

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值