我正在尝试编写二进制翻译器 - 将字符串作为输入,将其二进制表示作为输出.
我遇到了一些困难,我在变量中写了每个字母的翻译,但它们是变量,而不是字符串,所以我想从变量的名称中获取输入并打印结果:
a = "01000001"
b = "01000010"
c = "01000011"
d = "01000100"
# all the way to z
word = input("enter here: ")
print (word)
Run Code Online (Sandbox Code Playgroud)
当我运行这个时,我输入一个单词,它只是向我返回相同的单词,但是当我写print(a)它返回01000010但我无法使它与输入一起工作.
有人能告诉我我做错了什么吗?
我一直在尝试用 Python 制作游戏,但是当我移动角色时,它会留下痕迹。我知道它没有显示那么多,但如果你靠近,你可以看到小径,这真的让我很困扰。
这是我的代码:
import pygame
import os
from pygame import mixer
pygame.init()
mixer.init()
width = 800
height = 600
black = (0,0,0)
white = (255,255,255)
ship_width = 56
ship_height = 64
disp = pygame.display.set_mode((width,height))
pygame.display.set_caption("space_game")
clock = pygame.time.Clock()
background = pygame.image.load(os.path.join("Backgrounds", "Space.png"))
Ship00 = pygame.image.load(os.path.join("Images", "Animations", "Ship
Animation", "Ship00.png"))
Ship01 = pygame.image.load(os.path.join("Images", "Animations", "Ship
Animation", "Ship01.png"))
Ship02 = pygame.image.load(os.path.join("Images", "Animations", "Ship
Animation", "Ship02.png"))
Ship03 = pygame.image.load(os.path.join("Images", "Animations", "Ship
Animation", "Ship03.png"))
Ship04 = pygame.image.load(os.path.join("Images", "Animations", "Ship
Animation", "Ship04.png"))
Ship05 = …Run Code Online (Sandbox Code Playgroud) 我正在尝试用pygame制作游戏,我想循环播放音乐但是当我把它放在我的主循环中时它只重复第一秒.
import pygame
import os
from pygame import mixer
pygame.init()
mixer.init()
#here i have all the display settings and stuff so im not gonna write them
mixer.music.load(os.path.join("Music", "music.wav"))
mixer.music.play()
Run Code Online (Sandbox Code Playgroud)
我希望这个循环播放而不停止,但我不知道如何.