星期二, 5月 09, 2017

20170509_python_Python程式設計實務_練習小記

20170509_python_Python程式設計實務_練習小記

Github:

Client: openSUSE Leap 42.2 with vi and PyCharm

今天練習猜數字程式, 另外把 Pycharm 升級到 2017.1.2 版本
  • VCS 要 push 的時候必須要在console輸入github 帳密才能 push
    • Linux 版本有這個問題, Mac 沒有
      • 但是 linux 如果是 command line 去使用 /opt/pycharm-community-2017.1.2/bin/pycharm.sh 就可以, 目前原因待查

練習相關檔案

檔案: 5-3.py

# -*- coding: utf-8 -*-

import random

game_count = 0
all_counts = []
while True:
  game_count += 1
  guess_count = 0
  answer = random.randint(0,99)
  while True:
      guess = int(input("請猜一個數字(0-99)"))
      guess_count += 1
      if guess == answer:
          print("恭喜你,猜中了")
          print("你總共猜了" + str(guess_count) + "次")
          all_counts.append(guess_count)
          break;
      elif guess > answer:
          print("您猜的數字太大了")
      else:
          print("您猜的數字太小了")
  #這邊有發生 pycharm console輸入的 值會產生錯誤, 但是在 command line 下就沒有問題
  onemore = input("還要再玩一次嗎?(Y/N)")
  if onemore != 'Y' and onemore != 'y':
      print("歡迎下次再來玩")
      print("您的成績如下")
      print(all_counts)
      print("平均猜中次數" + str(sum(all_counts)/float(len(all_counts))))
      break;




~ enjoy it

1 則留言:

Philips Huges 提到...


Wonderful blog.. Thanks for sharing informative Post. Its very useful to me.

Installment loans
Payday loans
Title loans