-1

我一直在获得正确的编码。如果您碰巧运行此代码,请更正您认为合适的内容。我已经搜索过了,这里和那里仍然存在错误。这里是游戏编码。定义术语中可能存在一些问题,我仍在学习 Python 词汇来定义新项目,但没有找到正确的答案。这是您可以运行和尝试的代码。谢谢:

import random
import time

def displayIntro():
    print("You are in a city. In front of you,")
    print("you see two restraunts. In one pizzeria, the service is friendly")
    print("and will share thier free pizza with you. The other pizzeria")
    print("is very unpredictable and will hire you to wash the dishes in the back quick.!")
    print()

def choosePizzeria():
    pizzeria=""
    while((pizzeria != "1") and (pizzeria != "2")):
        print("Which pizzeria will you go into? (1 or 2) ")
        pizzeria = input()

    return pizzeria

def checkPizzeria(level,(pizzeria != "1") or (pizzeria != "2")):
    print("You approach the pizzeria and see people hustling in and out quickly...")
    time.sleep(2)
    print("It really crowded with people waiting in line, playing arcade games and just having a good time dancing...")
    time.sleep(2)
    print("A little manager with a suit steps in in front of you! He quickly slips his arm behind his back...")
    print()
    time.sleep(2)

    friendlypizzeria = random.randint(1, 3)
    overworkPizzeria = friendlypizzeria + 1
    if overworkPizzeria > 3:
      overworkPizzeria -= 3

    if chosenPizzeria == str(friendlyPizzeria):
        print("Hand you a slip of paper for two free pizzas!")
    elif chosenPizzeria == str(overworkPizzeria):
          print("He hands you a slip of paper telling you to watch the dishes in the back for a while since you stared at him too long!")
    else:
          level += 1
    if level < 3:
        print("You quickly hid behind some customes and head out to 3 more pizzerias")
    else:
        print("Congratulations you win two free pizzas and")
        print("you get to go to the manager's weekend party!!!! ")

    return level

playAgain = "yes"
while playAgain == "yes" or playAgain == "y":

    displayIntro()
    level = 0

    pizzeriaNumber = choosePizzeria()

    level = checkPizzeria(level,pizzeriaNumber)

    if level == 1:
        pizzeriaNumber = choosePizzeria()
        level = checkPizzeria(level,pizzeriaNumber)

    if level == 2:
        pizzeriaNumber = choosePizzeria()
        level = checkPizzeria(level,pizzeriaNumber)


    print('Do you want to play again? (yes or no)')
    playAgain = input()

谢谢你。

4

1 回答 1

1

主要是语法错误,我建议阅读一些 Python 文档。特别是关于类型和比较运算符。但下面会运行;

import random
import time

def displayIntro():
    print("You are in a city. In front of you,")
    print("you see two restraunts. In one pizzeria, the service is friendly")
    print("and will share thier free pizza with you. The other pizzeria")
    print("is very unpredictable and will hire you to wash the dishes in the back quick.!")
    print()

def choosePizzeria():
    pizzeria=""
    while((pizzeria != 1) and (pizzeria != 2)):
        print("Which pizzeria will you go into? (1 or 2) ")
        pizzeria = input()

    return pizzeria

def checkPizzeria(level, pizzariaNumber):
    print("You approach the pizzeria and see people hustling in and out quickly...")
    time.sleep(2)
    print("It really crowded with people waiting in line, playing arcade games and just having a good time dancing...")
    time.sleep(2)
    print("A little manager with a suit steps in in front of you! He quickly slips his arm behind his back...")
    print()
    time.sleep(2)

    chosenPizzeria = pizzariaNumber
    friendlypizzeria = random.randint(1, 3)
    overworkPizzeria = friendlypizzeria + 1
    if overworkPizzeria > 3:
      overworkPizzeria -= 3

    if chosenPizzeria == friendlypizzeria:
        print("Hand you a slip of paper for two free pizzas!")
    elif chosenPizzeria == overworkPizzeria:
          print("He hands you a slip of paper telling you to watch the dishes in the back for a while since you stared at him too long!")
    else:
          level += 1
    if level < 3:
        print("You quickly hid behind some customes and head out to 3 more pizzerias")
    else:
        print("Congratulations you win two free pizzas and")
        print("you get to go to the manager's weekend party!!!! ")

    return level



playAgain = "yes"
while playAgain == "yes" or playAgain == "y":

    displayIntro()
    level = 0

    pizzeriaNumber = choosePizzeria()

    level = checkPizzeria(level,pizzeriaNumber)

    if level == 1:
        pizzeriaNumber = choosePizzeria()
        level = checkPizzeria(level,pizzeriaNumber)

    if level == 2:
        pizzeriaNumber = choosePizzeria()
        level = checkPizzeria(level,pizzeriaNumber)


    print('Do you want to play again? (yes or no)')
    playAgain = raw_input()
于 2017-10-04T03:52:30.510 回答