在我的课程中,我的任务是创建一个Caesar Cipher解码器,它接受一串输入并使用字母频率找到最好的字符串.如果不确定有多大意义,但发布问题:
编写一个执行以下操作的程序.首先,它应该读取一行输入,即编码消息,并且将由大写字母和空格组成.您的程序必须尝试使用shift S的所有26个可能值来解码消息; 在这26条可能的原始信息中,打印出具有最高优点的信息.为方便起见,我们将为您预先定义变量letterGoodness,长度为26的列表,等于上面频率表中的值

到目前为止我有这个代码:
x = input()
NUM_LETTERS = 26 #Can't import modules I'm using a web based grader/compiler
def SpyCoder(S, N):
y = ""
for i in S:
x = ord(i)
x += N
if x > ord('Z'):
x -= NUM_LETTERS
elif x < ord('A'):
x += NUM_LETTERS
y += chr(x)
return y
def GoodnessFinder(S):
y = 0
for i in S:
if x != 32:
x = ord(i)
x -= ord('A')
y += letterGoodness[x]
return y …Run Code Online (Sandbox Code Playgroud) 所以我有这个代码,它做的应该是好的.我想要它做的是随机地按照不同的数量缩放正方形.我的问题在于blit功能,我的方块似乎只是向上扩展,因为blit不会删除旧形状,只是将新形状复制到表面.
如何使形状扩大和缩小,而不仅仅是扩展?
我的代码:
import sys, random, pygame
from pygame.locals import *
pygame.init()
w = 640
h = 480
screen = pygame.display.set_mode((w,h))
morphingShape = pygame.Surface((20,20))
morphingShape.fill((255, 137, 0)) #random colour for testing
morphingRect = morphingShape.get_rect()
def ShapeSizeChange(shape, screen):
x = random.randint(-21, 20)
w = shape.get_width()
h = shape.get_height()
if w + x > 0 and h + x > 0:
shape = pygame.transform.smoothscale(shape, (w + x, h + x))
else:
shape = pygame.transform.smoothscale(shape, (w - x, h - x))
shape.fill((255, 137, …Run Code Online (Sandbox Code Playgroud)