我有一个看起来像这样的字符串:
\n\xc2\xa325 - \xc2\xa330More than \xc2\xa330\xc2\xa320 - \xc2\xa325\xc2\xa320 - \xc2\xa325, More than \xc2\xa330, \xc2\xa325 - \xc2\xa330, \xc2\xa315 - \xc2\xa320, Up to \xc2\xa315\xc2\xa315 - \xc2\xa320\nRun Code Online (Sandbox Code Playgroud)\n即,它是按随机顺序组合在一起的多个范围,可能有或没有空格或逗号分隔符。
\n我想从中得到最大和最小值。我如何有效地做到这一点?我确信会有一个简单的正则表达式,但我看不到它
\n因此,我尝试使用GUI创建一种加密程序。这是代码:
import sys
from PyQt4 import QtGui, QtCore
import os
from Crypto.Hash import SHA256
from Crypto import Random
from Crypto.Cipher import AES
class Window(QtGui.QMainWindow):
def __init__(self):
super(Window, self).__init__()
self.setGeometry(50, 50, 500, 300)
self.setWindowTitle("Encryptionprogram")
self.setWindowIcon(QtGui.QIcon('pythonicon.png'))
self.container = QtGui.QWidget()
self.setCentralWidget(self.container)
self.container_lay = QtGui.QVBoxLayout()
self.container.setLayout(self.container_lay)
extractAction = QtGui.QAction("Leave", self)
extractAction.setShortcut("Ctrl+Q")
extractAction.setStatusTip("Leave the app")
extractAction.triggered.connect(self.close_application)
mainMenu = self.menuBar()
fileMenu = mainMenu.addMenu('&File')
fileMenu.addAction(extractAction)
#Inputs
self.Input = QtGui.QLineEdit("Filname", self)
self.Input.setFixedWidth(200)
self.Input.setFixedHeight(25)
self.Input.move(20, 200)
self.Input.setSizePolicy(QtGui.QSizePolicy.Fixed,
QtGui.QSizePolicy.Fixed)
self.Input2 = QtGui.QLineEdit("password", self)
self.Input2.setFixedWidth(200)
self.Input2.setFixedHeight(25)
self.Input2.move(220, 200)
self.Input2.setSizePolicy(QtGui.QSizePolicy.Fixed,
QtGui.QSizePolicy.Fixed)
self.home() …Run Code Online (Sandbox Code Playgroud) from numpy import *
x = np.random.randint(low=10, high=30, size=6)
print(x)
"C:\Users\Piistasyo\PycharmProjects\test project\venv\Scripts\python.exe" "C:/Users/Piistasyo/PycharmProjects/test project/loop.py"
Traceback (most recent call last):
File "C:/Users/Piistasyo/PycharmProjects/test project/loop.py", line 44, in <module>
x = np.random.randint(low=10, high=30, size=6)
NameError: name 'np' is not defined
Run Code Online (Sandbox Code Playgroud)
为什么我收到这个错误?请帮助我已经安装了 numpy 包
问题是:
编写一个函数 length,它接受一个列表作为输入。如果列表的长度大于或等于 5,则返回“Longer than 5”。如果长度小于 5,则返回“小于 5”。
到目前为止我有:
def length(x):
for lst in x:
if len(x) >= 5:
return "Longer than 5"
else:
return "Less than 5"
Run Code Online (Sandbox Code Playgroud)