python學習日記(二)

2021-10-02 04:35:56 字數 2330 閱讀 4571

題庫2

print("%.3f"%c)強制輸出c為3位小數

本題是乙個for迴圈使用,有一種順序排序法的感覺。

這道題debug了很久

own =

0reposit =

0c =

1d =

for i in

range(1

,13):

budget =

int(

input()

) a =

300+ own - budget

b = a //

100if a <0:

c =0-i)

else

:if b >=1:

reposit = reposit + b

own = a - b*

100else

: own = a

if c ==1:

print

(int

(reposit *

1.2*

100+ own)

)else

:print

(int

(d[0])

)

own =

0reposit =

0c =

1d =

for i in

range(1

,13):

budget =

int(

input()

) a =

300+ own - budget

b = a //

100if a <0:

c =0-i)

else

:if b >=1:

reposit = reposit + b

own = a - b*

100else

: own = a

if c ==1:

print

(int

(reposit *

120+ own)

)else

:print

(int

(d[0])

)

出現錯誤的測試點:

input

288

225151

95279

20365

300266

232199

60output_correct = 1477

output_error_code = 1476

出現錯誤的原因:

錯誤**最後輸出是deposit * 1.2 * 100 + own ; 這樣算出來的話是1476.999998,輸出的時候自己用的int(),而int()是向下取整。因此錯誤。

關鍵在於,為什麼會出來1476.99998 這個數???

簡單迴圈套迴圈

money =

1e10

req =

int(

input()

)for i in

range(3

):pen, pr =

map(

int,

input()

.split())

package = req // pen

a = req % pen

if a ==0:

b = package * pr

if money > b:

money = b

else

: b =

(package+1)

* pr

if money > b:

money = b

print

(money)

Python學習日記 二 list操作

l a b c d 1,2,3,e 4 在list的結尾新增乙個新的元素,沒有返回值,但會修改原列表 print l output a b c d 1,2,3,e 4 5 2.list.insert list.insert index,value 在指定的index插入乙個新的元素 l.insert...

python學習日記

動態語言和靜態語言最大的不同,就是函式和類的定義,不是編譯的時候定義的,而是執行時動態建立的.直接在類中定義的是類屬性,如 class student object name student 例項屬性必須通過例項繫結。如self.age xx 根據python的規則,定義時千萬不要把類屬性和例項屬性...

python學習日記

第一章 起步 第二章 變數和簡單資料型別 安裝vm模擬機和windows的python3.8.2和geany,編寫第乙個hello world。課後題,自動隨時排盤,自動解析每宮的程式。排盤,每宮每個專案代表含義,能量表示,時間動態變化 歷史查詢 print 輸出 n hello 變數 n.titl...