习题+作业:https://www.cnblogs.com/Eva-J/articles/11135411.html

# -*- coding: utf-8 -*-
__author__ = 'caiqinxiong_cai'
# 2019/7/9 17:45
'''
实现用户输入用户名和密码,当用户名为 seven 且 密码为 123 时,显示登陆成功,否则登陆失败!
'''
# username = 'seven'
# password = '123'
# input_name = input('please input the name:')
# input_password = input('please input the password:')
# if username == input_name and password == input_password:
# print('登陆成功!')
# else:
#     print('登陆失败!')

'''
实现用户输入用户名和密码,当用户名为 seven 且 密码为 123 时,显示登陆成功,否则登陆失败,失败时允许重复输入三次
'''
# username = 'seven'
# password = '123'
# n = 0
# while n < 3:
#     input_name = input('please input the name:')
#     input_password = input('please input the password:')
#     if username == input_name and password == input_password:
#         print('登陆成功!')
#         break
#     else:
#         print('登陆失败!')
#     n +=1

'''
实现用户输入用户名和密码,当用户名为 seven 或 alex 且 密码为 123 时,显示登陆成功,否则登陆失败,失败时允许重复输入三次
'''
# n = 0
# while n < 3:
#     input_name = input('please input the name:')
#     input_password = input('please input the password:')
#     if ('seven' == input_name or 'alex' == input_name)  and '123' == input_password:
#         print('登陆成功!')
#         break
#     else:
#         print('登陆失败!')
#     n +=1

'''
使用while循环实现输出2-3+4-5+6...+100 的和
'''
# n = 2
# sum = 0
# while n <= 100:
#     if n % 2 == 0:
#         sum = sum + n
#     else:
#         sum = sum - n
#     n +=1
# print('2-3+4-5+6...+100的和为:',sum)

'''
使用 while 循环实现输出 1,2,3,4,5, 7,8,9, 11,12
'''
# n = 0
# while n <12:
#     n +=1
#     if n == 10 or n == 6:
#         continue
#     elif n == 12:
#         print(n,end='')
#     elif n == 5 or n == 9:
#         print(n,end=', ')
#     else:
#         print(n,end=',')

'''
 使用 while 循环实现输出 1-100 内的所有奇数
'''
# n = 0
# while n < 100:
#     n +=1
#     if n % 2 == 0:
#         continue
#     print(n,end=',')

'''
 使用 while 循环实现输出 1-100 内的所有偶数
'''
# n = 0
# while n < 100:
#     n +=1
#     if n % 2 != 0:
#         continue
#     print(n,end=',')

'''
使用while 循环输出100-50,从大到小,如100,99,98…,到50时再从0循环输出到50,然后结束
'''
# n = 100
# m = 0
# while n >= 50:
#     print(n,end=',')
#     n -=1
# print()
# while m <= 50:
#     print(m,end=',')
#     m +=1

'''
使用while,完成以下图形的输出
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
'''

# n = 1
# m = 0
# while n <= 10:
#     if n < 5:
#         print("* " * n)
#     else:
#         m = m + 2
#         print("* " * (n - m))
#     n = n + 1

# -*- coding: utf-8 -*-
__author__ = 'caiqinxiong'
# 2019/7/9 17:22
my_name = 'caiqinxiong'
my_password = 'cai'
i = 2
while i >= 0:
    username = input('请输入用户名:')
    if username == my_name:
        j = 2
        while j >= 0:
            password = input('请输入密码:')
            if password == my_password:
                print('welcom!!')
                exit(-1)
            else:
                print('密码输入有误!')
                if j == 0:
                    print('账号已锁定,请10分钟后重新尝试!')
                    break
                else:
                    print('你还有%s次尝试机会!' % j)
            j -= 1

    else:
        print('账号输入有误!')
        if i != 0:
            print('你还有%s次尝试机会!' % i)
        else:
            print('账号已锁定,请10分钟后重新尝试!')
    i -= 1

 

# -*- coding:utf-8 -*-
# caiqinxiong 
# 2019/7/7 下午4:04
ball_list = []
while True:
    choice = input('请选择6个红球(红球的选择范围是1-32)')
    if choice.isdigit():
        choice= int(choice.strip())
        if choice > 0 and choice < 33:
            if choice in ball_list:
                print('选择的数字重复了!')
                continue
            ball_list.append(choice)
            print('选择的第\033[35;5m%s\033[5m个红球的号码为:\033[31;1m%s\033[0m' % (len(ball_list),choice))
        else:
            print('红球的选择超出范围!!')
        if len(ball_list) == 6:
            while True:
                choice = input('请选择2个蓝球(篮球的选择范围是1-16)')
                if choice.isdigit():
                    choice = int(choice.strip())
                    if choice > 0 and choice < 17:
                        if choice in ball_list:
                            print('选择的数字重复了!')
                            continue
                        ball_list.append(choice)
                        print('选择的第\033[36;5m%s\033[5m个蓝球的号码为:\033[34;1m%s\033[0m' % (len(ball_list)-6, choice))
                    else:
                        print('红球的选择超出范围!!')
                    if len(ball_list) == 8:
                        print('分割线'.center(50,'-'))
                        print('您选择的双色球的号码为:')
                        # print('\033[0;44;37m%s\033[0m' % ball_list)
                        for i in ball_list:
                            if ball_list.index(i) > 5:
                                print('\033[0;44;37m%s\033[0m' % i, end=' ')
                            else:
                                print('\033[41;1m%s\033[0m' % i, end=' ')
                        exit(-1)
                else:
                    print('请输入有效数字!')
    else:
        print('请输入有效数字!')

 

posted on 2019-07-12 11:52  雨之夜&秋  阅读(116)  评论(0)    收藏  举报