Ai
1 Star 0 Fork 0

Role/Python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
RandomNumberGame.py 1.77 KB
一键复制 编辑 原始数据 按行查看 历史
Shivansh-khare 提交于 2020-10-01 15:47 +08:00 . Create RandomNumberGame.py
'''
hey everyone it is a basic game code using random . in this game computer will randomly chose an number from 1 to 100 and players will have
to guess that which number it is and game will tell him on every guss whether his/her guess is smaller or bigger than the chosen number. it is
a multi player game so it can be played with many players there is no such limitations of user till the size of list. if any one wants to modify
this game he/she is most welcomed.
Thank you
'''
import os
import random
players=[]
score=[]
print("\n\tRandom Number Game\n\nHello Everyone ! it is just a game of chance in which you have to guess a number"
" from 0 to 100 and computer will tell whether your guess is smaller or bigger than the acctual number chossen by the computer . "
"the person with less attempts in guessing the number will be winner .")
x=input()
os.system('cls')
n=int(input("Enter number of players : "))
print()
for i in range(0,n):
name=input("Enter name of player : ")
players.append(name)
os.system('cls')
for i in range(0,n):
orignum=random.randint(1,100)
print(players[i],"your turn :",end="\n\n")
count=0
while True :
ch=int(input("Please enter your guess : "))
if ch>orignum:
print("no! number is smaller...")
count+=1
elif ch==orignum:
print("\n\n\tcongrats you won")
break
else :
print("nope ! number is large dude...")
count+=1
print(" you have taken", count+1,"attempts")
x=input()
score.append(count+1)
os.system('cls')
print("players :\n")
for i in range(0,n):
print(players[i],"-",score[i])
print("\n\nwinner is :\n")
for i in range(0,n):
if score[i]==min(score):
print(players[i])
x=input()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/CRole/Python.git
git@gitee.com:CRole/Python.git
CRole
Python
Python
master

搜索帮助