我知道如何使用while循环,但我不确定我需要发出命令来加倍前一个分数的部分。
任务是加倍或退出。
这是我目前的代码:
toHaveBeenCalled()
答案 0 :(得分:1)
无需定义新的var newnumber,只需重写Original
通过original = original*2
import random
play = 'y'
original = 1
while play.lower() == 'y':
chance = random.randint(0,3)
if chance == 0:
print("Unlucky.... better luck next time")
else:
original = original*2
print (original)
play = input("Play again?[y/n]: ")
答案 1 :(得分:1)
无需引入变量newnumber。另外,不要使用大小写变量的混合。
import random
play = 'y'
original = 1
while play.lower() == 'y':
chance = random.randint(0,3)
if chance == 0:
print("Unlucky.... better luck next time")
else:
original= original*2 # or shorthand: original *= 2
print (original)
play = input("Play again?[y/n]: ")
答案 2 :(得分:0)
如果您尝试将newNumber
变量加倍,则无需将Original = Original * 2
置于混合中。只是用
Original *= 2
(简称$res = $client->request('POST', 'https://fghfgh', [
'auth' => ['user', 'pw'],
'headers' => [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
]
]);
)。
答案 3 :(得分:0)
您将新变量值(original * 2)
分配给循环的本地范围变量,因此每次迭代original
仍为1.
import random
play = 'y'
original = 1
while play.lower() == 'y':
if (random.randint(0, 3) == 0):
print('Unlucky... better luck next time')
else:
original *= 2; print(original)
play = input('Play again? [y/n]: ')