print('我是预发环境')
print('Hello World!')
def bubble_sort(arr):
n = len(arr)
for i in range(n):
for j in range(0, n - i - 1):
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]
def main():
arr = [64, 34, 25, 12, 22, 11, 90]
print("原始数组:")
print(arr)
bubble_sort(arr)
print("排序后的数组:")
print(arr)
print(arr)
main()
def fibonacci(n):
if n <= 0:
return "输入的数应该为正整数。"
elif n == 1:
return [0]
elif n == 2:
return [0, 1]
else:
fib_list = [0, 1]
while len(fib_list) < n:
fib_list.append(fib_list[-1] + fib_list[-2])
return fib_list
print(fibonacci(10))
import random
def get_user_choice():
print("请输入你的选择:")
print("1. 石头")
print("2. 剪刀")
print("3. 布")
choice = int(input("请选择(1/2/3): "))
return choice
def get_computer_choice():
return random.randint(1, 3)
def determine_winner(user, computer):
if user == computer:
return "平局"
elif (user == 1 and computer == 2) or (user == 2 and computer == 3) or (user == 3 and computer == 1):
return "用户赢了"
else:
return "电脑赢了"
def main():
print("欢迎来到石头、剪刀、布游戏!")
user_choice = get_user_choice()
computer_choice = get_computer_choice()
print("电脑选择了:", computer_choice)
result = determine_winner(user_choice, computer_choice)
print("结果:", result)
main()
def intro():
print("欢迎来到文本冒险游戏!")
print("在这个游戏中,你将扮演一个勇敢的英雄,探索一个危机四伏的世界。")
print("你的决定将决定你的命运。祝你好运!")
print()
def choose_path():
print("你站在一个分叉路口。你可以选择向左走,也可以选择向右走。")
path = input("你要走哪条路?(左/右): ").lower()
if path == "左":
print("你选择了向左走。你遇到了一头狮子!")
lion_encounter()
elif path == "右":
print("你选择了向右走。你发现了一个宝箱!")
treasure_chest()
else:
print("无效的输入。请重新输入。")
choose_path()
def lion_encounter():
print("狮子看起来很饿,它向你扑来。")
action = input("你要做什么?(战斗/逃跑): ").lower()
if action == "战斗":
print("你勇敢地与狮子战斗,最终成功击败了它。你继续前进。")
treasure_chest()
elif action == "逃跑":
print("你试图逃跑,但狮子追上了你,将你杀死了。游戏结束。")
else:
print("无效的输入。请重新输入。")
lion_encounter()
def treasure_chest():
print("你找到了一个宝箱,里面装满了金币和珠宝。恭喜你赢得了游戏!")
intro()
choose_path()
# 图形输出测试
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [1, 4, 9, 16, 25]
plt.plot(x, y)
plt.title('Line Graph Example')
plt.xlabel('X Axis')
plt.ylabel('Y Axis')
plt.show()
import subprocess
import sys
subprocess.check_call([sys.executable, "-m", "pip", "install", "matplotlib"])
# 图形输出测试
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [1, 4, 9, 16, 25]
plt.plot(x, y)
plt.title('Line Graph Example')
plt.xlabel('X Axis')
plt.ylabel('Y Axis')
plt.show()
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return '''
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Python Web Page</title>
</head>
<body>
<h1>Hello, this is a web page generated by Python!</h1>
<p>Welcome to the Python-powered web page. Enjoy your stay!</p>
</body>
</html>
'''
if __name__ == '__main__':
app.run(debug=True)
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。