字符串

时间:2018-03-10 06:14:01

标签: python-3.x

我正在做一些事情,这不起作用,你能帮忙吗?

num1 = int(code1)
num2 = int(code2)
rnd = randint(num1, num2)
print(rnd)

错误: 我随机导入了randint!

ERRIR: in randint return self.randrange(a, b+1)

2 个答案:

答案 0 :(得分:0)

因此,如果您致电from email import encoders from email.mime.base import MIMEBase from email.mime.multipart import MIMEMultipart from io import StringIO email = MIMEMultipart() email['Subject'] = 'subject' email['To'] = 'recipient@example.com' email['From'] = 'sender@example.com' # Add the attachment to the message f = StringIO() # write some content to 'f' f.write("content for 'test.txt'") f.seek(0) msg = MIMEBase('application', "octet-stream") msg.set_payload(f.read()) encoders.encode_base64(msg) msg.add_header('Content-Disposition', 'attachment', filename='test.txt') email.attach(msg) ,您将收到错误消息。当第一个参数超过randint(10,5)方法中的第二个参数时,会出现此错误。如果你只想在num1和num2之间得到一个随机数,你可以通过一个小技巧解决这个错误

randint()

答案 1 :(得分:0)

对我来说很好。

也许你错过了一些小事?

from random import randint

code1 = '1'
code2 = '11'

num1 = int(code1)
num2 = int(code2)

rnd = randint(num1, num2)
print(rnd) #prints 3, but this may vary

这是你期望得到的吗?