2017-12-02 59 views
3

加法運算,我9歲的孩子試圖向我的算盤隨機數的數學自動化。我要生成隨機數,然後做對他們

我想隨機生成值,並將其存儲在內存中供以後,當我按下檢查加法。那麼它應該給出所有隨機數的附加值。

到目前爲止,我有這樣的代碼

# my abacus training app 

import random 
import time 

print ('hey what\'s your name') 
name = input() 

print("well today i am goingto ask abacus questions ") 

print ("choose a level") 
levelOne = print ("level 1") 
print (levelOne) 

choice = input() 

if choice.endswith("1") : 
    print("let's start") 
    noone = random.randint(1,10) 
    print (noone) 
    time.sleep(5) 
    notwo = random.randint(1,10) 
    print (notwo) 
    time.sleep(5) 
    nothree = random.randint(1,10) 
    print (nothree) 
    time.sleep(5) 
    nofour = random.randint(1,10) 
    print (nofour) 
    time.sleep(5) 
    nofive = random.randint(1,10) 
    print (nofive) 
    time.sleep(5) 

=======我張貼以上問題的最終答案,這是我最後的代碼,感謝SRIG和哈米德Temsah用於輸入==感謝所有支持我的人。

# my abacus training app 
 

 
import random 
 
import time 
 

 
print ('hey what\'s your name') 
 
name = input() 
 

 
print("well today i am goingto ask abacus questions ") 
 

 
print ("choose a level") 
 

 

 

 
choice = input("choose a level : ") 
 

 
if choice.endswith("1") : 
 
    print("let's start") 
 
    noone = random.randint(1,10) 
 
    print (noone) 
 
    time.sleep(10) 
 
    notwo = random.randint(1,10) 
 
    print (notwo) 
 
    time.sleep(10) 
 
    nothree = random.randint(1,10) 
 
    print (nothree) 
 
    time.sleep(10) 
 
    nofour = random.randint(1,10) 
 
    print (nofour) 
 
    time.sleep(10) 
 
    nofive = random.randint(1,10) 
 
    print (nofive) 
 
    time.sleep(10) 
 
    print ("click enter to check your ans") 
 
    input() 
 
    print(noone+notwo+nothree+nofour+nofive) 
 

+1

什麼是您收到的錯誤或問題,您所面對? – Ajax1234

+1

你想用這條線做什麼? 'levelOne = print(「level 1」)' – RottenCandy

+0

和PyGame在你的問題在哪裏?你爲什麼設置標籤'pygame'? – furas

回答

2

幹得9歲的孩子,你做得很好! 如果我清楚地理解了你的問題,你想要求用戶在這5個隨機數字生成後輸入另一個字符。如果有字符「+」,那麼你應該打印所有這些隨機數的總和,你可以重新使用自己的代碼來實現這一點,如:

operand = input() 
if operand.endswith("+") : 
    print(noone+notwo+nothree+nofour+nofive) 
+0

感謝它爲我工作,因爲我的爸爸總是說我不孤單......謝謝我所有的在 –

2

你可以不levelOne = print ("level 1")做,只是做print("level 1")因爲print()返回None。要確認這一點,請嘗試levelOne == None

if-statement後,您需要添加所有的數字和print的總和。

否則,你的代碼工作原樣。您可能要插入提示參數爲input(),就像這樣:

choice = input('Choose a level: ') 

希望有所幫助。

+0

以下發布完整的代碼,它幫助了很多...感謝很多Srig –