第一個自己完成的python程序,雙色球選購


    大學學習的是計算機專業,學過很多語言,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學習能夠堅持到底,加油!加油!加油!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM