大学学习的是计算机专业,学过很多语言,C,C++,Java,python,这么多年来,感觉每次都坚持不下去,这次网上参加了老男孩python7天训练营,这个作业也算自己通过自己的学习和构想写的第一个程序,心里还是觉得有点成就感,虽然很简单,但是都是自己想出来的,所以发出来分享一下:
双色球选购
1 双色球(假设一共八个球,6个红球,球号1-32、2个蓝球,球号1-16)
2 确保用户不能重复选择,不能超出范围
3 用户输入有误时有相应的错误提示
4 最后展示用户选择的双色球的号码
自己完成的代码:
1 red_ball = [ ] 2 blue_ball = [ ] 3 count = 0 4 print("Welcome to 小猿圈 lottery station") 5 while count < 6: 6 red_input = input("select red ball: ").strip() 7 if red_input.isdigit(): 8 red_input = int(red_input) 9 if red_input in red_ball: 10 print("number", red_input, "is already exist in red ball list") 11 elif red_input > 0 and red_input < 33: 12 red_ball.append(red_input) 13 count += 1 14 print([count],"select red ball:",red_input) 15 else: 16 print ("only can select n between 1-32") 17 while count < 8: 18 blue_input = input("select blue ball: ").strip() 19 if blue_input.isdigit(): 20 blue_input = int(blue_input) 21 if blue_input in blue_ball: 22 print("number", blue_input, "is already exist in red ball list") 23 elif blue_input > 0 and blue_input < 16: 24 blue_ball.append(blue_input) 25 count += 1 26 i = count - 6 27 print([i],"select blue ball:",blue_input) 28 else: 29 print ("only can select n between 1-16") 30 else: 31 print("Red ball:",red_ball,'\n',"Blue ball:",blue_ball,'\n',"Good Luck.")
以前每次学习编程都是半途而费,希望这次的python学习能够坚持到底,加油!加油!加油!