标签:logic stl opera table cat als ret sage rds
today,i learned so much knowledge about the basis of python.
firstly,i studied methematical operators like ‘+‘,‘/‘ and so on.
for instance,2*3=5 , 4/2=2.0 and so on.
And, i also knew about comparison operators like ‘>‘,‘<=‘,‘==‘ and the rest.
for exmple,2 < 3,2 <=3,3==3 and the rest.
afterwards,i mastered assigning operators like ‘=‘,‘+=‘,‘**=‘ etc.
in the end of morning,i grasped the usage of logical operator,and、or、not.
secondly,i knew a expression is a statement or code consisting of operands and operators ,like 1 * 3 * 4(1、3、4 stand for operand ,* stand for operator ),expressions can get value ,so put them on the right of "=" to assign value to a veriable.
thirdly,i mastered the usage of while loop ,so i spent the whole afternoon going about doing it.
the first program i writed(how to get odd number and even number):
num = 1
while num <= 100:
if num%2 == 0 :
print(num)
num += 1
and
num = 1
while num <= 100 :
if num%2 != 0 :
print(num)
num += 1
a program of guessing age:
age = 50
user_input_age = int(input("age is : "))
while user_input_age != age :
if user_input_age == age :
print("yes")
elif user_input_age > age :
print("bigger")
else :
print("smaller")
user_input_age = int(input("age is : "))
print("End")
or
age = 51
flag = True
while flag :
users_age = int(input("Age is "))
if users_age == age:
print("yes")
flag = False
elif users_age > age:
print("bigger")
else :
print("smaller")
print("End")
or(and the usage of ‘break‘)
age = 51
while True :
users_age = int(input("Age is "))
if users_age == age:
print("yes")
break
elif users_age > age:
print("bigger")
else :
print("smaller")
print("End")
and
num = 1
while num<10 :
print(num)
num += 1
if num == 3 :
break
a program of using # to get a rectangle :
num_height = 1
height = int(input("Please input the height of the retangle: "))
width = int(input("Please input the width of the retangle:"))
while num_height <= height :
num_width = 1
while num_width <= width :
print("#",end="")
num_width += 1
num_height += 1
print()
a way to get the multiplication table:
first = 1
while first <= 9 :
third = first
second = 1
while second <= third :
print(str(second)+"*"+str(third)+"="+str(second*third),end="\t")
second += 1
print()
first += 1
标签:logic stl opera table cat als ret sage rds
原文地址:https://www.cnblogs.com/margin1314/p/9058374.html