Python - 猜数字游戏
python
import random
def game(): tzxl8023.com
number_to_guess = random.randint(1, 100)
guess = None
attempts = 0
while guess != number_to_guess:
guess = int(input('猜一个1到100之间的数字: '))
attempts += 1
if guess < number_to_guess:
print('太小了!')
elif guess > number_to_guess:
print('太大了!')
print(f'恭喜你,你猜对了!用了{attempts}次尝试。')
if name == “main”:
game()
JavaScript (HTML内嵌) - 简单的点击计数器
html
0
<script>
let count = 0;
function incrementCount() {
count++;
document.getElementById('count').textContent = count;
}
</script>
Java - 简单的控制台程序(不是游戏,但类似) java import java.util.Scanner;
public