如何完成我的Python抛蛋游戏?

时间:2018-03-08 19:14:51

标签: python-3.x

当我开始时,我以为我已经牢牢掌握了我将如何去做,但是当我一直打字时,我开始迷失方向。我开始构建它是因为我刚学会了布尔和条件,所以我想尝试一下。

游戏的目的是首先猜出正确的数字,然后能够抛出一个特定的蛋,这样一致的清洁用品就会耗尽,以使汽车脱离“脏”状态。这不是一个有趣的游戏,但我想知道它会如何发展。

import random
name = input("hey, tell me your name!:")
print("well " + name + " if you can guess the number I'm thinking of, I'll let you throw an egg at my car")
number = random.randint (1, 100)
GuessesTaken = 0
Ammo = input('which egg will you use?')
How_hard = int(input('how hard do you throw?:\n\t'))
cleaning_supplies = ['windex', 'wipers', 'shamwow', 'sponge']
eggs = ['robin', 'ostrich', 'hen', 'Pterodactyls']
Velocity = {'robin' : 4, 'ostrich' : 10, 'hen' : 6, 'pterodactyls' : 15,}
pairings = {'windex' : 'robin', 'wipers' : 'ostrich', 'shamwow' : 'hen', 'sponge' : 'pterodactyles'}
# the eggs are hitting a car which then turns clean (false)
dirty = True
hit = cleaning_supplies.pop()
egg = (input(' :\n\t'))
while GuessesTaken < 5:
    guess = input("enter a num: ")
    GuessesTaken = GuessesTaken + 1
    guess = int(guess)
    if guess < number:
        print("Not High Enough!")
    elif guess > number:
     else:
     break

请不要完全输入正确的代码并提交,我只是在寻找一些线索。

为什么else语句下划线为错误?

1 个答案:

答案 0 :(得分:0)

要点:

def consider_guess(guess, target):
    if guess < target:
        return (False, "Too small")  # Read about tuples. Tuples are your friend.
    if guess > target:
        return (False, "Too big")
    # The only remaining possibility is equality.
    return (True, "Yes, you guessed it!")

while ...:
    guess = int(input_raw("Your guess? "))
    (is_correct, message) = consider_guess(guess, ...)
    print(message)
    if is_correct:
        break