附加作业01

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了附加作业01相关的知识,希望对你有一定的参考价值。

题目1

描述:

PyQt5 完成一个简单的计算器

代码:

import sys,os
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
def openc():
    os.system(‘calc.exe‘)
    return
def calc_name():
    name = nameLine.text()
    name = name.replace(‘(‘,‘(‘)
    name = name.replace(‘)‘,‘)‘)
    name = name.replace(‘PI‘,‘3.1415926‘)
    name = name.replace(‘pai‘,‘3.1415926‘)
    name = name.replace(‘π‘,‘3.1415926‘)
    name = name.replace(‘pi‘,‘3.1415926‘)
    name = name.replace(‘e‘,‘2.71828‘)
    name = name.replace(‘E‘,‘*10**‘)
    name = name.replace(‘^‘,‘**‘)
    if name == ‘‘:
        QMessageBox.information(nameLine,‘blank inputing‘,‘please input‘)
        return
    else:
        b = eval(name)
        QMessageBox.information(nameLine,‘Done!‘,‘result:  {:.2f}‘.format(b))

app = QApplication(sys.argv)
Enter = QWidget()
nameLabel = QLabel(‘calculate:‘)
nameLine = QLineEdit(Enter)
EnterButton = QPushButton(‘Enter‘,Enter)
CalcButton = QPushButton(‘Calc‘,Enter)
subLayout =QHBoxLayout()
subLayout.addWidget(CalcButton)
subLayout.addStretch(1)
subLayout.addWidget(EnterButton)
bodyLayout = QVBoxLayout()
bodyLayout.addWidget(nameLabel)
bodyLayout.addWidget(nameLine)
bodyLayout.addLayout(subLayout)
EnterButton.clicked.connect(calc_name)
CalcButton.clicked.connect(openc)
Enter.setLayout(bodyLayout)
Enter.setGeometry(300,200,400,100)
Enter.setWindowTitle(‘calculation‘)
Enter.show()
sys.exit(app.exec_())

  

 

题目2

描述:网页的保存

代码:

#!user/bin/python 3.5.2
#-*- encoding=utf-8   -*-
import requests
import os

url=input(‘please input a url:‘)
print (‘hold on several seconds‘)
if url[0:4]!="http":
    url=‘http://‘+url
kv={‘user-agent‘:‘Mozilla/5.0‘}
r=requests.get(url,headers =kv)
r.raise_for_status()
r.encoding=r.apparent_encoding
ans=input(‘save the webpage?(y or n)‘)
if ans==‘y‘:
    root=input(‘please input a path to save the webpage:‘)
    path=root+url.split(‘/‘)[-1]+‘.html‘
    if not os.path.exists(root):
        os.mkdir(root)
    if not os.path.exists(path):
        with open(path,‘wb‘) as f:
            f.write(r.content)
            f.close()
            print(‘success!‘)
    else:
        print(‘the file has existed‘)

  

 

以上是关于附加作业01的主要内容,如果未能解决你的问题,请参考以下文章

附加作业01

片段未附加到上下文 - 延迟的 UI 更改

附加作业01

片段事务分离和附加后ListView不工作?

带有神秘附加字符的 Javascript Date getTime() 代码片段

java 简单的代码片段,展示如何将javaagent附加到运行JVM进程