显示欢迎页面
显示游戏菜单
选择菜单玩游戏
猜数过程
显示GAME OVER
In [6]:
def win():
print(
'''
======恭喜你,你赢了=======
."". ."",
| | / /
| | / /
| | / /
| |/ ;-._
} ` _/ / ;
| /` ) / /
| / /_/\_/\
|/ / |
( ' \ '- |
\ `. /
| |
| |
======恭喜你,你赢了=======
'''
)
def lose():
print(
'''
======YOU LOSE=======
.-" "-.
/ \
| |
|, .-. .-. ,|
| )(__/ \__)( |
|/ /\ \|
(@_ (_ ^^ _)
_ ) \_______\__|IIIIII|__/__________________________
(_)@8@8{}<________|-\IIIIII/-|___________________________>
)_/ \ /
(@ `--------`
======YOU LOSE=======
'''
)
import random,math
def guss_game () :
n=int(input('please enter an integer as toplimit. '))
number=random.randint(1,n)
max_times=math.ceil(math.log2(n))
times=0
while times<max_times :
guss_num=int(input('please enter the number you guss. '))
times+=1
print('一共可以猜', max_times, '次')
print('你已经猜了', times, '次')
if guss_num==number :
win()
print('神秘数字是:', number)
print('你比标准次数少', max_times-times, '次')
break
elif guss_num>number :
print('Sorry,you guss biger . ')
else :
print('Sorry,you guss samller . ')
else :
lose()
print('this mystery number is ',number)
def menu ():
print('''
=====游戏菜单=====
1. 游戏说明
2. 开始游戏
3. 退出游戏
4. 制作团队
=====游戏菜单=====''')
def welcome():
print(
'''
======欢迎来到猜数游戏=======
/ \ , ,
_._ _ |oo| _ / \__/ \
_|||| ((/ () \)) / \
|||||/| ( ==== ) |oo|
\____/ _`\ /'_ / \
/ /.-' /\<>/\ `\.( () )_._
| ` / \/ \ /`'--'////)
\__,-'`| |. |\/ |/\/\|"\"`
| |. | \___/\___/
| |. | | |
======欢迎来到猜数游戏=======
'''
)
def game_over():
print(
'''
======GAME OVER=======
_________
/ ======= \
/ __________\
| ___________ |
| | - | |
| | | |
| |_________| |________________
\=____________/ )
/ """"""""""" \ /
/ ::::::::::::: \ =D-'
(_________________)
======GAME OVER=======
'''
)
def game_instruction ():
print('''
=================================
请输入一个数字作为猜数上限,
然后根据指示输入您所猜数字,
如果猜错则有您猜大了或小了的提示。
=================================''')
def workteam ():
print('''
制作人:山羊不吃天堂草
TEAM: 无敌小分队
赞助商: XXX特警''')
def main () :
welcome()
while True :
menu()
choice=int(input('please enter your choice. '))
if choice==1 :
game_instruction ()
elif choice==2 :
guss_game ()
elif choice==3 :
game_over()
break
else :
workteam()
if __name__ == '__main__':
main()
In [7]:
import random,math
n=int(input('please enter an integer as the number of integer you want to caculate . '))
m=int(input('please enter an integer as the downlimit. '))
k=int(input('please enter an integer as the toplimit. '))
i=0
sum=0
while i<n :
i+=1
number=random.randint(m,k)
sum+=number
print('the result is : ',math.sqrt(sum/n))
In [8]:
import random,math
n=int(input('please enter an integer as the number of integer you want to caculate . '))
m=int(input('please enter an integer as the downlimit. '))
k=int(input('please enter an integer as the toplimit. '))
i=0
sum1=0
sum2=0
while i<n :
i+=1
number=math.log(random.randint(m,k))
sum1+=number
sum2+=1/number
print('the first result is :',sum1)
print('the second result is :',sum2)
In [10]:
import random
n=int(input('please enter an integer as the number of integer you want to add. '))
i=0
sum=0
a=random.randint(1,9)
while i<n :
i+=1
sum+=a
a=a*10+a
print('the result is :',sum)
In [2]:
def menu ():
print('''
=====游戏菜单=====
1. 游戏说明
2. 开始游戏
3. 退出游戏
4. 制作团队
=====游戏菜单=====''')
def game_instruction ():
print('''
=================================
请输入一个数字作为被猜数,
然后计算机会输出它所猜数字,
如果猜错则请您输入大了或小了的提示。
=================================''')
def game_over():
print('GAME OVER !SEE YOU NEXT TIME')
def workteam ():
print('''
制作人:山羊不吃天堂草
TEAM: 无敌小分队
赞助商: XXX特警''')
def welcome():
print('WELCOME TO YOUR KINGDOM! ')
import random,math
def guss_game():
m=int(input('please enter an integer as lowerlimit. '))
n=int(input('please enter an integer as toplimit. '))
flag_number=int(input('please enter the number you set. '))
x=n-m
max_times=int(math.log2(x))
guss_times=0
while guss_times<max_times :
guss_times+=1
c_guss=random.randint(m,n)
print(c_guss)
print('计算机一共可猜',max_times,'次')
print('它已猜了',guss_times,'次')
if c_guss==flag_number :
print('Congratulation!the computer win!')
elif c_guss>flag_number :
input('c猜的数字')
n=c_guss-1
else :
input('c猜的数字')
m=c_guss+1
print('他剩余',max_times-guss_times,'次')
else :
print('poor c, your loss.')
def main () :
welcome()
while True :
menu()
choice=int(input('please enter your choice. '))
if choice==1 :
game_instruction ()
elif choice==2 :
guss_game ()
elif choice==3 :
game_over()
break
else :
workteam()
if __name__ == '__main__':
main()