In [2]:
n=0
n=n+2
print(n)
In [3]:
n=n+2
print(n)
In [4]:
n=n+3
print(n)
In [5]:
n=7
i=0
while i<n:
i=i+1
print(i)
In [10]:
print(10>5)
In [11]:
print(10<1.1)
In [14]:
flag=False
print(flag)
In [16]:
n=100
i=0
total=0
while i<n:
i=i+1
total=total+i
print(total)
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)
In [20]:
print("apple">"banana")
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)
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)
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)
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))
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 ')
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 ')