2017-12-02 61 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 –