2015-05-09 79 views

回答

3

只讓它作爲一個INT:

int(r) 

別叫變量的名稱相同的模塊,否則你就無法再訪問該模塊。這就是爲什麼我用r代替。

這就是說,你的比較應該反正工作,因爲Python是聰明的:

>>> 5.0 == 5 
True 

最後,因爲你顯然希望10 0多至90,我只是這樣做:

int(random.random() * 10) * 10 
+0

@LiamGiannini究竟是什麼? –

+0

@LiamGiannini它不起作用?問題是什麼?我無法讀懂你的想法。 –

2

>>> int(50.0)
50

使用int(表達式)將值轉換爲int。

+0

我剛剛檢查過,這對我有用。無論如何,我有活躍的Python 2.7.9(雖然我不認爲他們已經修改了這種行爲)。 – berendeanicolae

+0

active python 2.7.9 – berendeanicolae

+0

int(round(random.randrange(0,100)/ 10)* 10)爲我返回一個int – berendeanicolae

1

可以使用int功能

x=50.0 
x=int(x) 
相關問題