admin 管理员组

文章数量: 887169


2024年1月27日发(作者:criticalprocessdied)

python趣味编程代码

以下是一些趣味的Python编程代码示例:

猜数字游戏:

import random

number = t(1, 100)

guess = int(input("猜一个1到100之间的数字:"))

while guess != number:

if guess < number:

print("猜小了!")

else:

print("猜大了!")

guess = int(input("再猜一次:"))

print("恭喜,你猜对了!")

打印九九乘法表:

for i in range(1, 10):

for j in range(1, i+1):

print(f"{i} × {j} = {i*j}", end=" ")

print()

猜单词游戏:

import random

words = ["apple", "banana", "orange", "peach", "watermelon"]

word = (words)

hidden_word = "_" * len(word)

print("猜单词游戏!")

print(hidden_word)

while hidden_word != word:

guess = input("猜一个字母:")

new_hidden_word = ""

for i in range(len(word)):

if guess == word[i]:

new_hidden_word += guess

else:

new_hidden_word += hidden_word[i]

hidden_word = new_hidden_word

print(hidden_word)

print("恭喜,你猜对了!单词是", word)

这些代码示例可以让你在学习编程的同时体验一些趣味和挑战。你可以根据自己的兴趣和创造力进行更多的实验和改进。


本文标签: 编程 游戏 代码