我没事写了个代码,一运行就一直报错
代码如下
# -*- coding:utf-8 -*-
import pygame as p
import sys as s
result = input("Welcome!If you want to play the game,please enter 1,if you want to know the writer,please enter 2 ,if you want to exit,please enter 3,if you want to experience other functions,please enter 4")
if result == 1:
def game():
p.init()
size = width,height = 500,400
screen = p.display.set_mode(size)
color = (0,0,0)
ball = p.image.load("ball(1).jpg")
ballrect = ball.get_rect()
speed = [5,5]
clock = p.time.Clock()
while True:
clock.tick(60)
for event in p.event.get():
if event.type == p.QUIT:
s.exit()
ballrect = ballrect.move(speed)
if ballrect.left < 0 or ballrect.right > width:
speed[0] = -speed[0]
if ballrect.top < 0 or ballrect.bottom > height:
speed[1] = -speed[1]
screen.fill(color)
screen.blit(ball,ballrect)
p.display.flip()
p.quit()
game()
if result == 2:
print("Writer:ekl All Rights Reserved.")
if result == 3:
exit()
else:
result = input("the functions are developmenting and they're dangerous,Sure to use it?(Yes or No)")
if result == "Yes": #有问题
result = input("Plase choose the experiences 1.command 2.games 3.exit 4..........(only enter the numbers)")
if result == 1:
print("please write the command")
result = input("e.g:exit()")
if result == "exit()":
exit()
if result == "game()":
game()
else:
print("the command is wrong,the program will exit")
exit()
if result == 2:
pass
if result == 3:
exit()
else:
pass
if result == "No": #同样有问题
exit()
运行结果:
C:\Python27\python.exe C:/Users/Administrator/Desktop/pythonProject5/add.py
pygame 2.0.3 (SDL 2.0.16, Python 2.7.18)
Hello from the pygame community. https://www.pygame.org/contribute.html
Welcome!If you want to play the game,please enter 1,if you want to know the writer,please enter 2 ,if you want to exit,please enter 3,if you want to experience other functions,please enter 44
the functions are developmenting and they're dangerous,Sure to use it?(Yes or No)No
Traceback (most recent call last):
File "C:/Users/Administrator/Desktop/pythonProject5/add.py", line 40, in <module>
result = input("the functions are developmenting and they're dangerous,Sure to use it?(Yes or No)")
File "<string>", line 1, in <module>
NameError: name 'No' is not defined
Process finished with exit code 1
一直找不到问题