GithubHelp home page GithubHelp logo

python's Issues

Python 練習題(p.47-2)

回覆內容必須包含:

  • 學號
  • 姓名
  • 程式內容

提示:把程式碼放在如下的區塊中,可以保持縮排,並且提供語法高亮。

print('世界你好')

效果如下:

print('世界你好')

Python 練習題(p.48-3)

回覆內容必須包含:

  • 學號
  • 姓名
  • 程式內容

提示:把程式碼放在如下的區塊中,可以保持縮排,並且提供語法高亮。

print('世界你好')

效果如下:

print('世界你好')

#B10309042洪翌修

B10309042洪翌修

def get_int(msg, minimum, default): #定義一個函式 並且有3個參數
while True:
try:
line = input(msg) #將使用者輸入的資料暫存在line中來進行下面的判斷
if not line and default is not None:
return default #若有設定預設值則回傳default值
i = int(line) #將line的資料型態轉為int
if i < minimum: #若i小於minimum則出現must be >=minimum
print("must be >=", minimum)
else:
return i #若i符合條件則回傳i
except ValueError as err:
print(err)#若數值錯誤則出現錯誤訊息

rows = get_int("rows: ", 1, None) #將rows:後輸入的數字帶入上面的函式 且最小值為1 未設定預設值
columns = get_int("columns: ", 1, None) #將columns:後輸入的數字帶入上面的函式 且最小值為1 未設定預設值
minimum = get_int("minimum (or Enter for 0): ", -1000000, 0) #將minimum(or Enter for 0):後輸入的數字帶入上面的函式 且最小值是-1000000 預設值為0

default = 1000
if default < minimum:
default = 2 * minimum #若minimum大於1000則default等於2*minimum
maximum = get_int("maximum (or Enter for " + str(default) + "): ",
minimum, default )#把default變成字元並代入那一串,將maximum (or Enter for + str(default) + :)後輸入的數字帶入上面的函式
#最小值是上面輸入的minimum 預設值為上面的default

row = 0
while row < rows: #當row小於rows時執行下面的運算,且每迴圈一次row會+1
line = "" #先定義line來讓運算的結果填入
column = 0
while column < columns: #當column小於columns時執行下面的運算,且每迴圈一次column會+1
i = random.randint(minimum, maximum) #隨機生成介於minimum和maximum中的數字
s = str(i) #將生成的數字轉為字串
while len(s) < 10:
s = " " + s #讓數字包括空格共為10個字元
line += s #將結果存進line中
column += 1
print(line)
row += 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.