網站首頁 編程語言 正文
直接奔入主題看下面pywebio
程序,實現了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
程序,實現了Python的簡陋在線編輯器。
相對C++編輯器就比較復雜,需要調用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)
運行時會報一個錯,不用管它,跟咱們的程序無關。如果不是這個錯,那就是您的程序有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
相關推薦
- 2023-03-04 React使用redux基礎操作詳解_React
- 2023-07-08 git代碼回滾到某個tag
- 2022-05-20 springboot-mybatis實現增刪改查
- 2022-07-15 python新手練習實例之萬年歷_python
- 2022-10-09 C#實現線性查找算法_C#教程
- 2022-06-25 pytorch中permute()函數用法實例詳解_python
- 2022-03-15 feign.RetryableException: Read timed out executing
- 2022-12-22 使用PyCharm調試程序實現過程_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支