In [5]:
import random
number=random.randint(1,1000)
print(number)


681

In [12]:
import random,math
number=random.randint(1,1000)
print(math.log2(number))
print(math.ceil(math.log2(number)))
max_times=int(math.log2(number))
print(max_times)


9.800899899920305
10
9

In [14]:
i=0
while i<1000:
    print("i=",i)
    break
print("===========")
i=0
while i<1000:
    i+=1
    if i==100:
        print("the i in if ==",i)
        break
print("==========")
i=0
j=0
while i<5:
    print('i=',i)
    while j<100:
        print("j=",j)
        if j==2:
            print("break")
            break
        j+=1
    i+=1


i= 0
===========
the i in if == 100
==========
i= 0
j= 0
j= 1
j= 2
break
i= 1
j= 2
break
i= 2
j= 2
break
i= 3
j= 2
break
i= 4
j= 2
break

In [21]:
import random,math

m=int(input('please enter m :'))
k=int(input('please enter k :'))
n=int(input('please enter n'))
total=0
i=0

while i<n:
    i+=1
    total+=random.randint(m,k)
print(math.sqrt(total/n))


please enter m :1
please enter k :9
please enter n5
2.32379000772445

In [1]:
import random,math

n=int(input('plz enter n: '))
m=int(input('plz enter m: '))
k=int(input('plz enter k: '))

total1=0
total2=0
i=0
while i<n:
    temp=random.randint(m,k)
    total1+=math.log(temp)
    total2+=1/total1
    i+=1
print(total1,total2,sep='    ')


plz enter n: 9
plz enter m: 1
plz enter k: 9
12.737288958943898    1.816068701548853

In [11]:
import math,random

i=0
single=random.randint(1,9)
total=0
temp=0
n=int(input('plz enter n :'))

while i<n:
    temp=(10*temp+single)
    i+=1
    print("tempt",temp)
    total+=temp
    print('total',total)
print('the toal number is : ',total)


plz enter n :5
tempt 7
total 7
tempt 77
total 84
tempt 777
total 861
tempt 7777
total 8638
tempt 77777
total 86415
the toal number is :  86415

In [1]:
import random, math


def win():
    print("Haha, quite so easy! ")
    
def lose():
    print("Hum...I bet I'll win the next time!")

def game_over():
    print("See you~")

def show_team():
    print('''programmed,designed and sponsored by: Wanqiong Xie
    Thanks for my teacher though I don't know who he is(X)
    Sending you times of kisses~(Actually I won't do that, I promiss)''')

def show_instruction():
    print('''First enter the biggest number you may hold in your mind
    Then I will guess a number and tell you what it is
    If the number is smaller than the one you are thinking about, please tell me bigger
    If the number is bigger than that, please tell me smaller
    Otherwise please tell me bingo
    Have a good time!''')

def menu():
    print('''=====MENU=====
                1. how to play
                2. start game
                3. quit
                4. info
             =====MENU=====''')
             
def guess_game():
    n = int(input('Please enter the biggest number you may guess'))
    max_times = math.ceil(math.log(n, 2))
    chances = 0
    a=1
    b=n
    
    while chances<=max_times:
        guess=int((a+b)/2)
        print(guess,", right?")
        judge=input()
        if judge=="smaller":
            b=guess
        elif judge=="bigger":
            a=guess
        else :
            win()
            break
        chances+=1
    if chances>max_times :
        lose()
        
        

# 主函数
def main():
    while True:
        menu()
        choice = int(input('Please enter your choice: '))
        if choice == 1:
            show_instruction()
        elif choice == 2:
            guess_game()
        elif choice == 3:
            game_over()
            break
        else:
            show_team()


#主程序
if __name__ == '__main__':
    main()


=====MENU=====
                1. how to play
                2. start game
                3. quit
                4. info
             =====MENU=====
Please enter your choice: 1
First enter the biggest number you may hold in your mind
    Then I will guess a number and tell you what it is
    If the number is smaller than the one you are thinking about, please tell me bigger
    If the number is bigger than that, please tell me smaller
    Otherwise please tell me bingo
    Have a good time!
=====MENU=====
                1. how to play
                2. start game
                3. quit
                4. info
             =====MENU=====
Please enter your choice: 4
programmed,designed and sponsored by: Wanqiong Xie
    Thanks for my teacher though I don't know who he is(X)
    Sending you times of kisses~(Actually I won't do that, I promiss)
=====MENU=====
                1. how to play
                2. start game
                3. quit
                4. info
             =====MENU=====
Please enter your choice: 2
Please enter the biggest number you may guess50
25 , right?
bigger
37 , right?
bigger
43 , right?
smaller
40 , right?
smaller
38 , right?
bingo
Haha, quite so easy! 
=====MENU=====
                1. how to play
                2. start game
                3. quit
                4. info
             =====MENU=====
Please enter your choice: 3
See you~

In [ ]: