python programming foundation 1

Keywords: Python

Print printing
 print("Hello world! ""
#Output results
 Hello world!
#Assignment and printing
name = "Lai qingbo"
print("My name is",name)
#Output result
My name is Lai qingbo
#Assignment and printing
name = "Lai qingbo"
name2 =name
print("My name is",name2)
#Output result
My name is Lai qingbo
#Annotation line
#My name is Lai qingbo
#Notes for multiple rows
''''''
a='''
My name is Lai qingbo. 
My name is Lai qingbo!
'''
print(a)
#Output result
My name is Lai qingbo. 
My name is Lai qingbo!
#Input printing
 Name = input("Name:") × xxx
 Age = input("age:") × 30
 Job = input("work:") (salesman)
Salary = input("salary:") (2000)
info ='''
-----'' + Name + '' data-----
Name: '+ name +' '
Age: '' + age + ''
Work: '' '+ Job +' ''
Salary: '+ salary +' '
'''
print(info)
#Output results
 -----xxx's information-----
Name: xxx
 Age: 30
 Job: Salesman
 Salary: 2000
#Input printing
 Name = input("Name:")
Age = input("age:")
Job= input("work:")
Salary = input("salary:")
info ='''
-----%s information-----
Name:%s
 Age:%s
 Work:%s
 Salary:%s
'''%(Name,Name,Age,Job,Salary)
print(info)
#Output results
 -----xxx's information-----
Name: xxx
 Age: 30
 Job: Salesman
 Salary: 2000
#Input printing
'''
By default, all input in python is characters. If you want to set it as a number, you must convert it.
type() character type
 int() to number
'''
Name = input("Name:")
Age = int(input("age:))
print(type(Age))
Job= input("work:")
Salary = input("salary:")
info ='''
-----Data of {0}-----
Name: {0}
Age: {1}
Work: {2}
Salary: {3}
'''.format(Name,Age,Job,Salary)
print(info)
#Output results
 -----xxx's information-----
Name: xxx
 Age: 30
 Job: Salesman
 Salary: 2000
#ciphertext
import getpass
username =  input("User name:")#abc
password =  getpass.getpass("Password:")#123 ciphertext when input here
print(username,password)
#Output result
abc 123
#Password verification login
import getpass
_username = "abc"
_password = "123"
username =  input("User name:")
password =  getpass.getpass("Password:")#Ciphertext is entered here
if _username ==username and _password ==password :
    print("{name} welcome back!".format(name=username))
else:
    print("Wrong user name or password!")
#Clear text authentication login
_username = "laiqingbo"
_password = "laiqb1318"
username =  input("User name:")
password =  input("Password:")

if _username ==username and _password ==password :
    print("{name} welcome back!".format(name=username))
else:
    print("Wrong user name or password!")
#Clear text authentication login
_username = "laiqingbo"
_password = "laiqb1318"
username =  input("User name:")
password =  input("Password:")

if _username ==username and _password ==password :
    print("%s welcome back!"%(username))
else:
    print("Wrong user name or password!")
#Guess the number
number = 45
guess_number= int(input("Guess the number:"))
if guess_number == number:
    print("Congratulations, you guessed it right!")
elif guess_number > number:
    print("Think small!")
else:
    print("Think big!")
#for cycle
for i in range(10):#Cycle ten times-----for i in range(0,10,7 Software directory structure specification):#Cycle ten times, print only one difference, starting from 0
    print("Printing first%s second"%(i))

for i in range(0,10,2):#Cycle ten times, only print the difference of 2, starting from 0
    print("Printing first%s second"%(i))

for i in range(0,10,3):#Cycle ten times, only print the difference of three, starting from 0
    print("Printing first%s second"%(i))
#Guess numbers (for loop - limit ten times)
number = 45
for i in range(10):#Cycle ten times
    print("Now let's start%s Second guess number"%(i+1))
    guess_number = int ( input ( "Guess the number:" ) )
    if guess_number == number:
        print ( "Congratulations.%s Guess right!" %(i+1))
        break#Exit, break the ring
    elif guess_number > number:
        print ( "Think small!" )
    else:
        print ( "Think big!" )
else:
    print("You have more than ten times. Welcome to come again next time!")
#while Loop
count = 0
while True:
    print("Frequency:",count)
    count = count + 1
#Guess numbers (while loop)
number = 45
count = 0
while True:
    count = count + 1
    print("Now let's start%s Second guess number"%(count))
    guess_number = int ( input ( "Guess the number:" ) )
    if guess_number == number:
        print ( "Congratulations.%s Guess right!"%(count) )
        break#Exit, break the ring
    elif guess_number > number:
        print ( "Think small!" )
    else:
        print ( "Think big!" )
#Guess numbers (while loop - limit three times)
number = 45
count = 0
while True:
    count = count + 1
    if count >3:
        print("You have been more than three times. Please come again next time!")
        break
    print("Now let's start%s Second guess number"%(count))
    guess_number = int ( input ( "Guess the number:" ) )
    if guess_number == number:
        print ( "Congratulations.%s Guess right!"%(count) )
        break#Exit, break the ring
    elif guess_number > number:
        print ( "Think small!" )
    else:
        print ( "Think big!" )
#Guess numbers (while loop - limit three times)
number = 45
count = 0
while count <3:
    count = count + 1
    print("Now let's start%s Second guess number"%(count))
    guess_number = int ( input ( "Guess the number:" ) )
    if guess_number == number:
        print ( "Congratulations.%s Guess right!"%(count) )
        break#Exit, break the ring
    elif guess_number > number:
        print ( "Think small!" )
    else:
        print ( "Think big!" )
else:
    print("You have been more than three times. Please come again next time!")
#Guess the number (while loop - every three queries to exit)
number = 45
count = 0
while count <3:
    count = count + 1
    print("Now let's start%s Second guess number"%(count))
    guess_number = int ( input ( "Guess the number:" ) )
    if guess_number == number:
        print ( "Congratulations.%s Guess right!"%(count) )
        break#Exit, break the ring
    elif guess_number > number:
        print ( "Think small!" )
    else:
        print ( "Think big!" )
    if count == 3:
        shifoujixu =input("Do you want to keep playing?")
        if shifoujixu != "n":
            count =0
#Guess the number (while loop - every three queries to exit)
number = 45
count = 0
while True:
    count = count + 1
    print("Now let's start%s Second guess number"%(count))
    guess_number = int ( input ( "Guess the number:" ) )
    if guess_number == number:
        print ( "Congratulations.%s Guess right!"%(count) )
        break#Exit, break the ring
    elif guess_number > number:
        print ( "Think small!" )
    else:
        print ( "Think big!" )
    n = count / 3
    if n.is_integer():
        shifoujixu =input("Do you want to keep playing?")
        if shifoujixu == "n":
            print("look forward to seeing you next time!")
            break
#continue to jump out of this cycle

#Break break break cycle, jump out of the layer cycle
#Double circulation
for i in range(10):#Cycle ten times
    print("Printing first%s second"%(i))
    for j in range ( 10 ):#Cycle ten times
        print ( "%s" % (j) )
Out of small cycle of double cycle
for i in range(10):#Cycle ten times
    print("Printing first%s second"%(i))
    for j in range ( 10 ):
        print ( "%s" % (j) )
        if j >5:
            break
Published 1 original article · praised 0 · visited 2
Private letter follow

Posted by DarkShadowWing on Wed, 19 Feb 2020 09:54:09 -0800