怎么取出python中的字符串_如何从字符串中取出值?Python

我的任务是创建一个偏移因子,它基于程序前面计算的8个字符的键。首先,需要将8个字符密钥中的每个字符转换为等效的ascii数字,然后相加,然后将结果除以8,然后向下舍入为整数。最后,需要从该值中减去32。在

这是我在偏移因子之前的代码:def EncryptCode():

userFileLoad = input("Name the file and directory you want to load with the ending '.txt':\n")

with open (userFileLoad,mode="r",encoding="utf=8") as encrypt_file:

encrypt = encrypt_file.read()

print ("Code that will be encrypted:")

printMessage(encrypt)

eightNumKey = (chr(random.randint(33,126)) for _ in range(8))

print('\nEight-Character Key:', "".join(eightNumKey))

这就是我试图在程序中实现偏移因子的方法:

^{pr2}$

我的输出显示:This program has three choices.

1. Encrypt a message.

2. Decrypt the message.

3. Exit the program.

Make your choice: 1

Name the file and directory you want to load with the ending '.txt':

Sample.txt

Code that will be encrypted:

Somewhere in la Mancha, in a place whose name I do not care to remember, a gentleman lived not long ago, one of those who has a lance and ancient shield on a shelf and keeps a skinny nag and a greyhound for racing.

Eight-Character Key: txJ#K_P`

Traceback (most recent call last):

File "N:\Computer Science\Course Work\Controlled assessment\Controlled Assessment.py", line 54, in

showMenu()

File "N:\Computer Science\Course Work\Controlled assessment\Controlled Assessment.py", line 38, in showMenu

EncryptCode()

File "N:\Computer Science\Course Work\Controlled assessment\Controlled Assessment.py", line 26, in EncryptCode

offsetFactor = offsetFactor + ord(eightNumKey)

TypeError: ord() expected string of length 1, but generator found

参与评论 您还未登录,请先 登录 后发表或查看评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:数字20 设计师:CSDN官方博客 返回首页

打赏作者

weixin_39882623

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值