In [2]:
n=0
n=n+2
print(n)


2

In [3]:
n=n+2
print(n)


4

In [4]:
n=n+3
print(n)


7

In [5]:
n=7
i=0
while i<n:
    i=i+1
    print(i)


1
2
3
4
5
6
7

In [10]:
print(10>5)


True

In [11]:
print(10<1.1)


False

In [14]:
flag=False
print(flag)


False

In [16]:
n=100
i=0
total=0
while i<n:
    i=i+1
    total=total+i
print(total)


5050

In [19]:
n=int(input("plz input an int number: "))
i=0
total=0
while i<n:
    i=i+1
    total=total+i
print(total)


plz input an int number: 5
15

In [20]:
print("apple">"banana")


False

In [21]:
a = True
b = False
print(a and b)
print(False and b)
print(a or b)
print(b or True)
print(not a)
print(not b)
print(not a and b)


False
False
True
True
False
True
False

In [25]:
#练习1:仿照任务2完整代码,打印n!。
n = int(input("plz input an int: "))
i = 0
fact = 1
while i<n:
    i = i+1
    fact = fact*i
print(fact)


plz input an int: 5
120

In [1]:
name = input('plz enter your name and end with Enter:')
print('hello',name)
n = int(input('plz enter an int and end with Enter'))
m = int(input('plz enter an int and end with Enter'))
print('the sum of these two numbers is: ', m+n)
print('bye!',name)


plz enter your name and end with Enter:Cathleen
hello Cathleen
plz enter an int and end with Enter3
plz enter an int and end with Enter4
the sum of these two numbers is:  7
bye! Cathleen

In [4]:
#练习2:仿照实践1,写出由用户指定整数个数,并由用户输入多个整数,并求和的代码。
t = int(input('How many numbers do you want? '))
sum = 0
i = 1
while i <= t:
    m = int(input('plz enter an int and end with Enter: '))
    sum = sum + m
    i = i + 1
print('The sum is : ' + str(sum))


How many numbers do you want? 3
plz enter an int and end with Enter: 2
plz enter an int and end with Enter: 4
plz enter an int and end with Enter: 5
The sum is : 11

In [12]:
#练习3:用户可以输入任意多个数字,直到用户不想输入为止。
m = input('plz enter an int and end with Enter(press "e" to exit): ')
while m != 'e':
    m = input('plz enter an int and end with Enter(press "e" to exit): ')
print('Bye ')


plz enter an int and end with Enter(press "e" to exit): 3
plz enter an int and end with Enter(press "e" to exit): 5
plz enter an int and end with Enter(press "e" to exit): e
Bye 

In [1]:
#练习4:用户可以输入任意多个数字,直到输入所有数字的和比当前输入数字小,且输入所有数字的积比当前输入数字的平方小。
m = int(input('plz enter an int and end with Enter: '))
total = m
product = m
while m <= total or m * m <= product:
    m = int(input('plz enter an int and end with Enter: '))
    total = total + m
    product = product * m
print('Bye ')


plz enter an int and end with Enter: 1
plz enter an int and end with Enter: 2
plz enter an int and end with Enter: -1
plz enter an int and end with Enter: -2
plz enter an int and end with Enter: 0
plz enter an int and end with Enter: -1
plz enter an int and end with Enter: -2
Bye