Guess words

guess words#猜单词游戏

import#导入随机库

#import函数

words=(“easy”,"different","game","jumble","python","anwser","answer","pose","position","phone")#这些作为单词库调用

print(“--欢迎参加猜单词游戏!--”)

print(“--请把乱序后的字母组成一个单词”)

print('\n')

#设计封面

is_continue="y" #把字母y赋予函数

while is_continue=="y" or is_continue=="Y"

#新建乱序后的单词

jumble=while word:

position random

jumble+=word[position]

print("乱序后的单词:",jumble)

guess=input

while guess!=corrent and guess!=""

print(“对不起不正确”)

guess=input("请再猜一次")

if guess==corrent:

print("真厉害,您猜对啦!")

is_continue=input()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
#include <iostream>#include <random>#include <string>#include <algorithm>#include <cctype>using namespace std;const int MAX_WRONG = 6;const string WORDS[] = {"HELLO", "WORLD", "COMPUTER", "PROGRAMMING", "LANGUAGE"};const int NUM_WORDS = sizeof(WORDS) / sizeof(string);int main() { random_device rd; mt19937 gen(rd()); uniform_int_distribution<> dis(0, NUM_WORDS - 1); char playAgain = 'y'; while (tolower(playAgain) == 'y') { string word = WORDS[dis(gen)]; int wrongGuesses = 0; string guessedSoFar(word.size(), '_'); string lettersGuessed; cout << "Welcome to Hangman. Good luck!\n\n"; while (wrongGuesses < MAX_WRONG && guessedSoFar != word) { cout << "You have " << MAX_WRONG - wrongGuesses << " incorrect guesses left.\n"; cout << "You've used the following letters:\n" << lettersGuessed << endl; cout << "So far, the word is:\n" << guessedSoFar << endl; char guess; cout << "\nEnter your guess: "; cin >> guess; guess = toupper(guess); if (lettersGuessed.find(guess) != string::npos) { cout << "You've already guessed " << guess << endl; continue; } lettersGuessed += guess; if (word.find(guess) != string::npos) { cout << "That's right! " << guess << " is in the word.\n"; for (int i = 0; i < word.size(); ++i) { if (word[i] == guess) { guessedSoFar[i] = guess; } } } else { cout << "Sorry, " << guess << " isn't in the word.\n"; ++wrongGuesses; } } if (wrongGuesses == MAX_WRONG) { cout << "\nYou've been hanged!"; } else { cout << "\nYou guessed it!"; } cout << "\nThe word was " << word << endl; cout << "Do you want to play again? (y/n): "; cin >> playAgain; } return 0;}优化这段代码
05-25

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值