python-双色球选择程序-闰年判断

#现有如下两个变量,请根据执行结果解释原因
a = 123#--->内存中开辟一个空间123,变量a指向空间123
b = a#---->将变量b也指向空间123
a = 234#--->内存中开辟一个空间234,变量a此时由空间123,转头指向了空间234
print(a,b)


#制作趣味模板程序(编程题)

"""
需求:等待用户输入名字、地点、爱好,根据用户的名字和爱好进行任意显示
如:敬爱可爱的xxx,最喜欢在xxx地方干xxx
"""
input_str = input('请输入您的名字,地点,爱好!请用用空格隔开:')

name = input_str.split()[0]
site = input_str.split()[1]
hobby = input_str.split()[2]
print('敬爱可爱的{name},最喜欢在{site}地方干{hobby}'.format(name=name,hobby=hobby,site=site))


#输入一年份,判断该年份是否是闰年并输出结果。(编程题)
"""
注:凡符合下面两个条件之一的年份是闰年。 (1) 能被4整除但不能被100整除。 (2) 能被400整除。
"""
input_year = int(input('请输入年份:'))
if input_year % 400 == 0 or (input_year % 4 == 0 and input_year % 100 != 0):
print('{0}是闰年'.format(input_year))
else:
print('{0}不是闰年'.format(input_year))


#双色球彩票 选购程序
"""
1,先让用户依次选择6个红球,再选择2个蓝球,最后统一打印用户选择的球号。
2,确保用户不能选择重复的,选择的数不能超出范围。
3,红球1-32之间,篮球1-16
"""
print("欢迎来到双色球彩票选购,请开始您的选择")
count = 0
red_ball_list = []
blue_ball_list =[]
len_union_lotto = len(red_ball_list)+len(blue_ball_list)#红色与蓝色球的列表长度(去重后)
while len_union_lotto<8:#这里用两个球加起来的列表长度做判断,保证输入重复的数字后,不减少选择的次数
if len_union_lotto<6:
red_ball_num = int(input('请输入您选择的红球:'))#注意强转为int类型
if red_ball_num in list(range(1,32)):
if red_ball_num in red_ball_list:#判断输入的输入数字是否在红色池中
print('您选择的红球{}已经存在,请重新选择'.format(red_ball_num))
else:
red_ball_list.append(red_ball_num)#不在红球池时添加到红球池中
print('您选择的红球是:{}'.format(red_ball_num))
else:
print('红球只能选择1-32之间的数')

else:
blue_ball_num = int(input('请输入您选择的蓝球:'))
if blue_ball_num in list(range(1,16)):
if blue_ball_num in blue_ball_list:
print('您选择的蓝球{}已经存在,请重新选择'.format(blue_ball_num))
else:
blue_ball_list.append(blue_ball_num)
print('您选择的蓝球是:{}'.format(blue_ball_num))
else:
print('蓝球只能选择1-16之间的数')
print('用户选择的红色球有:{}'.format(red_ball_list))
print('用户选择的蓝色球有:{}'.format(blue_ball_list))



"""
使用while,完成以下图形的输出
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
"""
line_num = 1
while line_num < 10:
if line_num <6:
print(str(line_num)+'.'+"* "*line_num)
else:
print(str(line_num)+'.'+"* "*(10-line_num))
line_num+=1
 

猜你喜欢

转载自www.cnblogs.com/shanshan-test/p/12540036.html