用户:
KK飞_hhh查看:3 回复:2 评论:3 创建时间:2022-11-20T12:14:57
【作品展示】

【作品介绍】
瞎做的,不咋好玩。
【作品源代码】
import time
import random
print('切记!本游戏中您只能输入数字!并且在这段等待时间内禁止输入!否则报错,后果自负。(游戏将在5秒后自动开始)')
time.sleep(5)
zuixiaofanwei = input('欢迎来到猜数游戏,这个数最小是几?(电脑随机得出的数的范围)')
zuidafanwei = input('这个数最大是几?(电脑随机得出的数的范围)')
caicecishu = input('你可以猜几次?')
a = random.randint(int(zuixiaofanwei), int(zuidafanwei))
cishu = 0
for i in range(int(caicecishu)):
if (cishu == 0):
caishu = input('随便猜个你刚才输入的范围之间的数吧,然后输入进来。')
if (int(a) < int(caishu)):
print('大了,')
shengli = 0
elif (int(a) > int(caishu)):
print('小了,')
shengli = 0
else:
print('WC!NB啊!一发入魂!')
shengli = 1
break
cishu = 1
else:
caishu = input('再猜一次吧。')
if (int(a) < int(caishu)):
print('大了,')
shengli = 0
elif (int(a) > int(caishu)):
print('小了,')
shengli = 0
else:
print('这么久才猜对,太逊了!')
shengli = 1
break
if (int(shengli) == 1):
print('如果好玩可以重新启动程序再玩一次。')
else:
print('都猜那么多次了你还没猜对,逊喵了!不服可以重启游戏再玩一次。')
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn
音律猫猫import random
import time
#!usr/bin/python3
# coding=utf-8
secret = random.randint(1, 3)
number = int(input('The number is any number between 1-3,answer:'))
if (number == secret):
print('yes')
else :
print('no')
number = int(input("Sorry, you guessed wrong, but it's OK. You can do it again,then,The number you guessed was:"))
if (number == secret):
print('yes,bingo!thanks you playing!You can restart and play again!')
else :
print("no,you lose,I don't want to,You have to restart the game......")
print("right key:",secret)
time.sleep(1)点赞3
评论
捉虫代码大师为您转化为c++
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
void Start();
void GetResults();
int i, j, life, maxrand;
char c;
void Start() {
i = 0;
j = 0;
life = 0;
maxrand = 6;
cout << "Select difficulty mode:\n"; // the user has to select a difficutly level
cout << "1 : Easy (0-15)\n";
cout << "2 : Medium (0-30)\n";
cout << "3 : Difficult (0-50)\n";
cout << "or type another key to quit\n";
c = 30;
cin >> c; // read the user's choice
cout << "\n";
switch (c) {
case '1':
maxrand = 15; // the random number will be between 0 and maxrand
break;
case '2':
maxrand = 30;
break;
case '3':
maxrand = 50;
break;
default:
exit(0);
break;
}
life = 5; // number of lifes of the player
srand((unsigned)time(NULL)); // init Rand() function
j = rand() % maxrand; // j get a random value between 0 and maxrand
GetResults();
}
void GetResults() {
if (life <= 0) { // if player has no more life then he loses
cout << "You lose !\n\n";
Start();
}
cout << "Type a number: \n";
cin >> i;
if((i>maxrand) || (i<0)) { // if the user number isn't correct, restart
cout << "Error: number not between 0 and \n" << maxrand;
GetResults();
}
if(i == j) {
cout << "YOU WIN!\n\n"; // the user found the secret number
Start();
} else if(i>j) {
cout << "Too BIG\n";
life = life - 1;
cout << "Lives remaining: " << life << "\n\n";
GetResults();
} else if(i<j) {
cout << "Too SMALL\n";
life = life - 1;
cout << "Lives remaining: " << life << "\n\n";
GetResults();
}
}
int main() {
cout << "** Jackpot game **\n";
cout << "The goal of this game is to guess a number.\n";
cout << "Jackpot will tell you if the number is too big or too\n";
cout << "喵all compared to the secret number to find.\n\n";
Start();
return 0;
}点赞2
评论