In [1]:
import math,random
def c_sqrt():
n=int(input('请输入一个整数,以回车键结束'))
m=int(input('请输入一个整数,以回车键结束'))
k=int(input('请输入一个整数,以回车键结束'))
i=0
total=0
num=0
while i<n:
num=random.randint(m,k)
total=total+num
i=i+1
total=math.sqrt(total/n)
print(total)
c_sqrt()
In [3]:
import math,random
def c_log():
n=int(input('请输入一个整数,以回车键结束'))
m=int(input('请输入一个整数,以回车键结束'))
k=int(input('请输入一个整数,以回车键结束'))
i=0
total=0
num=0
while i<n:
num=random.randint(m,k)
num=math.log10(num)
total=total+num
i=i+1
print(total)
c_log()
In [1]:
import math,random
def c_fac():
n=int(input('请输入一个整数,以回车键结束'))
m=int(input('请输入一个整数,以回车键结束'))
k=int(input('请输入一个整数,以回车键结束'))
i=0
num=0
total=0
temp=0
j=0
num=random.randint(m,k)
while i<n:
temp=num
i=i+1
while j<i:
temp=temp*10
temp=temp+num
total=total+temp
j=j+1
print(total)
c_fac()
In [ ]:
import random
def welcome():
print(
'''
======欢迎来到猜数游戏=======
/ \ , ,
_._ _ |oo| _ / \__/ \
_|||| ((/ () \)) / \
|||||/| ( ==== ) |oo|
\____/ _`\ /'_ / \
/ /.-' /\<>/\ `\.( () )_._
| ` / \/ \ /`'--'////)
\__,-'`| |. |\/ |/\/\|"\"`
| |. | \___/\___/
| |. | | |
======欢迎来到猜数游戏=======
'''
)
def win():
print(
'''
======恭喜你,你赢了=======
."". ."",
| | / /
| | / /
| | / /
| |/ ;-._
} ` _/ / ;
| /` ) / /
| / /_/\_/\
|/ / |
( ' \ '- |
\ `. /
| |
| |
======恭喜你,你赢了=======
'''
)
def lose():
print(
'''
======YOU LOSE=======
.-" "-.
/ \
| |
|, .-. .-. ,|
| )(__/ \__)( |
|/ /\ \|
(@_ (_ ^^ _)
_ ) \_______\__|IIIIII|__/__________________________
(_)@8@8{}<________|-\IIIIII/-|___________________________>
)_/ \ /
(@ `--------`
======YOU LOSE=======
'''
)
def game_over():
print(
'''
======GAME OVER=======
_________
/ ======= \
/ __________\
| ___________ |
| | - | |
| | | |
| |_________| |________________
\=____________/ )
/ """"""""""" \ /
/ ::::::::::::: \ =D-'
(_________________)
======GAME OVER=======
'''
)
def game():
num=int(input('请输入一个整数,作为被猜数,以回车键结束'))
n=int(input('请输入一个整数,作为猜的次数,以回车键结束'))
i=0
c_num=0
while i<n:
c_num=random.randint(1,1000)
if(c_num==num):
print(win())
elif(c_num<num):
c_num=random.randint(c_num,1000)
i=i+1
else:
c_num=random.randint(1,c_num)
i=i+1
if(c_num==num):
print(win())
else:
print(lose())
print(game_over())
welcome()
game()
In [ ]: