주제
관용구를 채우고, 빈칸이 포함된 관용구를 무작위로 출력하고, 답을 채우고 맞는지 판단하고, 맞으면 2점을 더하고, "맞아, 대단해"를 출력하고, 틀렸으면 2점을 빼고, "틀리다"를 출력하고, 그리고 정답을 표시합니다. 채워진 것이 없으면 양식은 이 관용구를 무시하고 "over"를 출력합니다. 이 게임에는 총 8개의 레벨이 있으며 게임이 끝나면 결과가 출력되며 플레이어의 초기 점수는 20점입니다.
랜덤은 내장 모듈 random을 사용하여 달성할 수 있습니다.
결과 표시
소스 코드
# -*- coding: utf-8 -*-
# @Course : python 基础
# @Time : 2023/7/2 14:21
# @Author : Eden Wei
# @FileName: 石头剪刀布.py
# @Software: PyCharm 2022.1.3 (Professional Edition)
import random
player_score = 0
computer_score = 0
count = 0
print('''
* * * * * * * 欢迎来到4399游戏平台* * * * * * *
石头 剪刀 布
* * * * * * * * * * * * * * * * * * * * * * *
''')
player_name = input('请输入玩家姓名:')
print('1.貂蝉 2.曹操 3.诸葛亮')
computer_choice = input('请输入电脑角色:')
if computer_choice == '1':
computer_choice = '貂蝉'
elif computer_choice == '2':
computer_choice = '曹操'
elif computer_choice == '3':
computer_choice = '诸葛亮'
else:
print('选择错误,隐藏角色!')
computer_choice = '匿名'
print(player_name, 'VS', computer_choice)
while True:
count += 1;
player_fist_choice = eval(input('----------请出拳: 1.石头 2.剪刀 3.布---------'))
if player_fist_choice == 1:
player_fist_name = '石头'
elif player_fist_choice == 2:
player_fist_name = '剪刀'
elif player_fist_choice == 3:
player_fist_name = '步'
else: # 用户输入的不是1,2,3,随机选择
print('输入错误,随机选择')
player_fist_choice = random.randint(1, 3)
player_fist_name = ['石头', '剪刀', '布'][player_fist_choice - 1]
print(player_name, '出拳:', player_fist_name)
# 电脑出拳
computer_fist_choice = random.randint(1, 3)
computer_fist_name = ['石头', '剪刀', '布'][computer_fist_choice - 1]
print(computer_choice, '出拳', computer_fist_name)
print('我', player_fist_choice)
print('他', computer_fist_choice)
# 判断结构,谁赢谁输,有三种结果,平,输,赢
if computer_fist_choice == player_fist_choice:
print('平局')
elif (player_fist_choice == 1 and computer_fist_choice == 2) or \
(player_fist_choice == 2 and computer_fist_choice == 3) or \
(player_fist_choice == 3 and computer_fist_choice == 1): # 玩家赢
print(player_name, '大获全胜,不服再战啊')
player_score += 1
else:
print(computer_choice, '胜利')
computer_score += 1
answer = input('再来一局不?y/n')
if answer != 'y':
break
# 判断总比分
# 判断总比分
print('-' * 100)
print(player_name, 'VS', computer_choice)
print(f'一共对战了:{
count}局') # 第一次直播讲了
print(player_name, '得分:', player_score)
print(computer_choice, '得分:', computer_score)
if player_score == computer_score:
print('不分上下,平分秋色')
elif player_score > computer_score:
print(player_name, '最终胜利')
else:
print(f'大下无敌,我是:{
computer_choice}')