gpt4 book ai didi

python - 基本 Python 数据验证

转载 作者:太空宇宙 更新时间:2023-11-03 21:28:55 26 4
gpt4 key购买 nike

所以我正在参加 GSCE,我们的任务是创建一个简单的基于文本的游戏。我试图添加一些数据验证来向我的老师展示我可以做到,但事实证明......我做不到......对于任何精通Python的人来说,这可能看起来真的很容易,但出于某种原因当我运行该程序时,它有一个“无效语法”,所以我解决了这个问题(通过简单地添加一个“:”),但随后它说缩进是错误的?数据验证即将开始,您可以选择“向左”或“向右”;如果您输入“左”或“右”以外的任何内容,我希望它再次向您提供问题...请有人帮忙! (也请忽略垃圾故事)。

import time
import sys

print("Mars: 2040. The human race has been wiped out of existence by the alien race. Will you suffer the same fate?")
time.sleep(3)
name=input("What is your name?")

def start()
print("Okay",name,", which direction would you like to go? Left or right?")
direction=input()

if direction == "left":
print("You turn the corner to discover a large, wolf-life monster. It erupts in deafening roar and proceeds towards you.")
print("You enter the room and see a bow (and arrow) on the ground next to a sword. Which do you take? *Bow* or *sword*?")
weapon=input()

if weapon == "bow":
print("You fire the arrow into one of the eyes of the large monster. It stumbles, but stays on it's feet")
print("Nice hit! What now? *Shoot again* or *reach for your pocket*?")
weapon2=input()

if weapon2 == "shoot again":
print("You pull back the string and release. It soars over the head of the monster. The monster raises it's leg and stamps on your puny head.")
time.sleep(3)
print("GAME OVER")
exit()

if weapon2 == "reach for your pocket":
print("You pull out a sharp knife and throw it towards the monster. it strikes the leg of the monster and it crumbles to the ground. You run over, grabbing th eknife as you do and stab the monster in it's red, glowing eye. You win!")
time.sleep(4)
print("Congratulations! You win!!1! :D")
print("Game created by Tom Jolley.")

elif weapon == "sword":
print("You take a large, over-exaggerated swing... the sword falls to the ground with a loud bang as you dropped it 1 foot away from you because it was ''too heavy''... the monster stares at you you for a moment and it stamps on your head.")
time.sleep(5)
print("GAME OVER")
exit()

elif direction == "right":
print("You turn the corner to discover a ginormous arachnid drooling and staring at you with it's 8 glowing red eyes. It proceeds towards you.")
print("...well no, that's not a direction... just stand there..")
print("You enter the room and see a bow (and arrow) on the ground next to a sword. Which do you take? *Bow* or *sword*?")
weapon=input()

if weapon == "bow":
print("You fire the arrow into one of the eyes of the large monster. It stumbles, but stays on it's feet")
print("Nice hit! What now? *Shoot again* or *reach for your pocket*?")
weapon2=input()

if weapon2 == "shoot again":
print("You pull back the string and release. It soars over the head of the monster. The monster raises it's leg and stamps on your puny head.")
time.sleep(3)
print("GAME OVER")
exit()

if weapon2 == "reach for your pocket":
print("You pull out a sharp knife and throw it towards the monster. it strikes the leg of the monster and it crumbles to the ground. You run over, grabbing th eknife as you do and stab the monster in it's red, glowing eye. You win!")
time.sleep(4)
print("Congratulations! You win!!1! :D")
print("Game created by Tom Jolley.")

elif weapon == "sword":
print("You take a large, over-exaggerated swing... the sword falls to the ground with a loud bang as you dropped it 1 foot away from you because it was ''too heavy''... the monster stares at you you for a moment and it stamps on your head.")
time.sleep(5)
print("GAME OVER")
exit()


else:
print()
start()

start()

最佳答案

这里主要是一个空格问题,有很多是 8 个空格而不是 4 个,有些地方是 5 个

import time
import sys

print("Mars: 2040. The human race has been wiped out of existence by the alien race. Will you suffer the same fate?")
time.sleep(3)
name=input("What is your name?")

def start()
print("Okay",name,", which direction would you like to go? Left or right?")
direction=input()

if direction == "left":
print("You turn the corner to discover a large, wolf-life monster. It erupts in deafening roar and proceeds towards you.")
print("You enter the room and see a bow (and arrow) on the ground next to a sword. Which do you take? *Bow* or *sword*?")
weapon=input()

if weapon == "bow":
print("You fire the arrow into one of the eyes of the large monster. It stumbles, but stays on it's feet")
print("Nice hit! What now? *Shoot again* or *reach for your pocket*?")
weapon2=input()

if weapon2 == "shoot again":
print("You pull back the string and release. It soars over the head of the monster. The monster raises it's leg and stamps on your puny head.")
time.sleep(3)
print("GAME OVER")
exit()

if weapon2 == "reach for your pocket":
print("You pull out a sharp knife and throw it towards the monster. it strikes the leg of the monster and it crumbles to the ground. You run over, grabbing th eknife as you do and stab the monster in it's red, glowing eye. You win!")
time.sleep(4)
print("Congratulations! You win!!1! :D")
print("Game created by Tom Jolley.")

elif weapon == "sword":
print("You take a large, over-exaggerated swing... the sword falls to the ground with a loud bang as you dropped it 1 foot away from you because it was ''too heavy''... the monster stares at you you for a moment and it stamps on your head.")
time.sleep(5)
print("GAME OVER")
exit()

elif direction == "right":
print("You turn the corner to discover a ginormous arachnid drooling and staring at you with it's 8 glowing red eyes. It proceeds towards you.")
print("...well no, that's not a direction... just stand there..")
print("You enter the room and see a bow (and arrow) on the ground next to a sword. Which do you take? *Bow* or *sword*?")
weapon=input()

if weapon == "bow":
print("You fire the arrow into one of the eyes of the large monster. It stumbles, but stays on it's feet")
print("Nice hit! What now? *Shoot again* or *reach for your pocket*?")
weapon2=input()

if weapon2 == "shoot again":
print("You pull back the string and release. It soars over the head of the monster. The monster raises it's leg and stamps on your puny head.")
time.sleep(3)
print("GAME OVER")
exit()

if weapon2 == "reach for your pocket":
print("You pull out a sharp knife and throw it towards the monster. it strikes the leg of the monster and it crumbles to the ground. You run over, grabbing th eknife as you do and stab the monster in it's red, glowing eye. You win!")
time.sleep(4)
print("Congratulations! You win!!1! :D")
print("Game created by Tom Jolley.")

elif weapon == "sword":
print("You take a large, over-exaggerated swing... the sword falls to the ground with a loud bang as you dropped it 1 foot away from you because it was ''too heavy''... the monster stares at you you for a moment and it stamps on your head.")
time.sleep(5)
print("GAME OVER")
exit()


else:
print()
start()

start()

关于python - 基本 Python 数据验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53656840/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com