I. Assignment
# print (' HEllo world! ') #显示括号内内容
# name = ' Gu Jun ' # defines the variable just to use his value in the back.
#name = "Let ' Go"
#print (name)
#conent = ' Let ' go ' handsome ' ' #三引号有多行注释的功能, can also define strings, strings when displaying single and double quotes in domestic
#print (conent)
#age = 122 #中文可以当变量名
#print (Gu Jun) #int type does not need to be quoted
Age = 10
Name = ' Small white ' #字符串类型 string
Score = ' 89.22 ' #浮点型 float
Print (type age) # type See what type of variable is
Print (Type (name))
Two. Conditional judgment
#age = #条件判断语句 If ... else If ... So...
#if age<18:
# Print (' Minors ')
#else:
# print (' adult ')
# age=input (' Please enter your age ') #input input
# age=i NT (age) #类型转换
# if age<18:
# Print (' Minors ')
# Else:
# print (' adult ')
# score = input (' Please enter your score ') #多条件 To determine
# score = Int (score)
# if score >:
# Print (' excellent ')
# elif score>=75 and score<90: #同时满足两个条件用an D
# print (' good ')
# elif score>=60 and score<75: #elif multiple criteria, connect with elif
# print (' Pass ')
# Else:
# Print (' fail ')
sex = input (' Please enter gender; ') #or satisfy any one of the conditions
if sex!= ' man ' and sex!= ' woman ': #判断是否等于用 = = Not equal to use! =
Print (' Gender unknown ')
Else:
Print (' Gender legal ')
Practice
Import Random #随机产生
num = Random.randint (1,10) #随机产生一个1-10 number
Print (num)
New_num = input (' Please enter what number you want to guess: ')
new_num = Int (new_num) #数据类型转换
If New_num>num: #判断
Print (' big input ')
Elif New_num<num:
Print (' The number you entered is too small ')
Else
Print (' Sex legal ')
Three. For loop
# for I in range (101): #i默认从0开始每次循环加1 Range () Number of cycles
# If i%2==0:
# Print (' Even is ', i)
# if Else
#while
#for
#字符串格式化
Import datetime
Today=datetime.date.today () #取当前系统日期
Username=input (' Please enter user name: ')
#welcome = ' Welcome to ' +username #第一种方式
Welcome= ' welcome:%s Today's date is%s '% (username,today) #%s called a stand character
Print (Welcome)
#%s string %d integer
Four. While...else
# count=0
# while Count<3:
# If count==2:
# print (' 22222 ')
#
# Count+=1
# Else:
# print (' End of loop!! ‘)
#while loop corresponds to an else, the loop executes after the normal end.
Num=5
Count = 0 # Set counter
While Count < 3:# set loop judgment
Guess = input (' Please enter the number you want to guess ')
guess = Int (guess)
If guess > num:
Print (' You guessed it's big ')
#continue # to end this loop and continue the next loop
Elif Guess < num:
Print (' You guessed it's small ')
Else
Print (' You're right ', num)
Break
Count = count + 1 # Set counter +1
Else
Print (' Number of games reached ')
Six. If loop
#重复的去做一件事情
#循环, iteration, and traversal are all referred to as loops
#for
#while Cycle
#while must have a counter
Import Random
Num=random.randint (1,100)
Count = 0 #设置计数器
While count<10: #设置循环判断
Import Random # randomly generated
Guess = input (' Please enter the number you want to guess ')
guess = Int (guess)
If guess > num:
Print (' You guessed it's big ')
Continue #到这里结束本次循环, continue with the next loop
Elif Guess<num:
Print (' You guessed it's small ')
Continue
Else
Print (' You're right ')
Break
Count=count +1 #设置计数器 +1
#循环时, is the repetition of what's inside the loop.
#break re-loop within the encounter break immediately end no matter whether the loop is not over
#continue encounter continue in the loop then end this cycle and proceed to the next loop
# count-=1
# count=count-1
# count+=1
# count=count+1
# count*=1
# count=count*1
else: #循环正常结束之后做的操作
Print ()
Homework
Import datetime
Ty=datetime.date.today ()
Count=0
While count<3:
Username = input (' Please enter user name ')
passwd = input (' Please enter password ')
Name= ' Gujunqi '
Wd= ' 123456 '
U= "
If Username==name and PASSWD==WD and username! = U and Passwd!=u:
Print ('%s Welcome to login today is:%s '% (username,ty))
Break
Else
Print (' Account or password input error ')
Count+=1
Else
Print (' You have exhausted the number of times ')
Python Automation the next day-python