網(wǎng)站首頁 編程語言 正文
直接奔入主題看下面pywebio
程序,實現(xiàn)了Python的簡陋在線編輯器
from pywebio.input import * from pywebio.output import put_text from os import system,remove try: ? ? code = textarea('Code Edit Online', code={'mode': "python",'theme': 'darcula'}, value='# input your code here\n') ? ? with open('temp.py','w',encoding = 'utf-8') as f: ? ? ? ? f.write(code) ? ? system('python temp.py') ? ? put_text('成功運行程序') except Exception as e: ? ? put_text('運行:錯誤 at %s' % e)
主要使用了pywebio
程序,實現(xiàn)了Python的簡陋在線編輯器。
相對C++編輯器就比較復(fù)雜,需要調(diào)用g++.exe,可能在您的電腦上,就不見得能用了,需要把Dev-C++安裝到我這個位置,程序才可以運行,您可以修改程序。
from pywebio.input import * from pywebio.output import put_text from sys import path from os import system,remove try: ? ? system('chcp 65001 >nul') ? ? code = textarea('Code Edit Online ( C++ )', code={'mode': "python",'theme': 'darcula',}, value='// input your code here.\n') ? ? with open('temp.cpp','w',encoding='utf-8') as f: ? ? ? ? f.write(code) ? ? put_text('成功運行程序') ? ? system(r'D:\Dev-C++\Dev-cpp\MinGW64\bin\g++.exe "%s\temp.cpp" -o "%s\temp.exe" && call "%s\temp.exe" && pause' % (path[0],path[0],path[0])) ? ? remove('temp.cpp') ? ? remove('temp.exe') except Exception as e: ? ? put_text('運行:錯誤 at %s' % e)
運行時會報一個錯,不用管它,跟咱們的程序無關(guān)。如果不是這個錯,那就是您的程序有BUG
。
from pywebio.input import * from pywebio.output import put_text from sys import path from os import system,remove try: ? ? system('chcp 65001 >nul') ? ? code = textarea('Code Edit Online ( C++ )', code={'mode': "python",'theme': 'darcula',}, value='// input your code here.\n') ? ? with open('temp.cpp','w',encoding='utf-8') as f: ? ? ? ? f.write(code) ? ? put_text('成功運行程序') ? ? system(r'D:\Dev-C++\Dev-cpp\MinGW64\bin\g++.exe "%s\temp.cpp" -o "%s\temp.exe" && call "%s\temp.exe" && pause' % (path[0],path[0],path[0])) ? ? remove('temp.cpp') ? ? remove('temp.exe') except Exception as e: ? ? put_text('運行:錯誤 at %s' % e)
測試程序,直接運行第一個,輸入一段Python代碼:
maxNumber = 100 numbers = [] min = 2 numberSum = 0 for i in range(1,101): ? ? numbers.append(i) ? ?? while min <= maxNumber: ? ? is_prime = True ? ? for i in range(2,min): ? ? ? ? if (min % i) == 0: ? ? ? ? ? ? is_prime = False ? ? ? ? ? ? break ? ? if is_prime == True: ? ? ? ? numbers.remove(min) ? ? min += 1 print(numbers)
點擊藍色按鈕,觀察控制臺:
成功。
再測C++,測試代碼如下(C++:畫桃心):
// Author:PanDaoxi #include <iostream> using namespace std; int main(){ ?? ?for(double y=1.5;y>-1.5;y-=0.1){ ?? ??? ?for(double x=-1.5;x<1.5;x+=0.05){ ?? ??? ??? ?double a=x*x+y*y-1; ?? ??? ??? ?char b=(a*a*a-x*x*y*y*y<=0.0?'*':' '); ?? ??? ??? ?cout<<b; ?? ??? ?} ?? ??? ?cout<<endl; ?? ?} ?? ? ?? ?return 0; }
輸入測試程序并提交,觀察控制臺:
控制臺上多了個大桃心,成功運行。
原文鏈接:https://blog.csdn.net/PanDaoxi2020/article/details/122763331
相關(guān)推薦
- 2023-02-27 一文帶你學(xué)習(xí)C/C++中的<Windows.h>庫_C 語言
- 2022-04-25 C#中使用DevExpress中的ChartControl實現(xiàn)極坐標圖的案例詳解_C#教程
- 2023-03-22 Python裝飾器使用方法全面梳理_python
- 2023-09-12 git 忽略掉不需要的文件
- 2022-08-15 百行代碼實現(xiàn)基于Redis的可靠延遲隊列_Redis
- 2022-08-28 Spring Boot整合ElasticSearch
- 2022-09-02 ORACLE正則匹配查詢LIKE查詢多個值檢索數(shù)據(jù)庫對象_oracle
- 2022-07-15 SQL?Server中的游標介紹_MsSql
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支