Python Weekend jobs

Source: Internet
Author: User

#练习一:
If True or False and false:
Print (' Yes ')
Else
Print (' No ')
#输出结果为 Why?


if (True or False) and false:
Print (' Yes ')
Else
Print (' No ')

#输出结果为 Why?

Because and the operation priority is higher than or, so the first one, first, the operation Fales and False, is false, in the operation True or FALSE, is true. Output Yes

The parentheses are first operation in parentheses, true or false, is true, and false, is false.

#练习二: Write if multi-branch, guess old boy's age

tag=True
WhileTag
Age=Input if int (age) >50:
print ( Big"
continue
elif int (age) <50:
Print ( ' small ')
continue
else:
print ( ' correct ')
tag=false


#练习三: The user enters the user name password authentication, validates passes into the sub-loop, enters the command, if the command is Q, exits all loops

While1:
Name=Input' Input your Name: ')
Pwd=Input if name== " Zuo ' and pwd== " 123 ':
break
while 1:
Res=input (" ==>: ')
if res== ' Q ':
break
else:
Print (



#练习四: Loops out all elements in the tuple: # t= (1,2,3,4,5,6,7,8,9)

Mode one: While and for (by index),

# for I in range (len (t)):
# Print (t[i],end= ")

Way two: Do not follow the index way

# for I in T:
# Print (i,end= ")

#练习五: Iterate through the list and all the elements in the sub-list
l=[1,2,[3,4],[5,6]]

l=[1,2,[3,4],[5,6]]
L
Type (i) = =List:
In I:
Print (j)
Else
Print (i)

#练习六: Printing
‘‘‘
*
***
*****
*******

For IInchRange0,5):
For JInchRange1,5-i):
Print‘ ‘,End=‘‘)
for J in range (1,2*i):
print (end=< Span style= "color: #008080; Font-weight:bold ">")
for J in range (1, 5-i):
print (", end = ")
print ()


#练习七: Printing
‘‘‘
*****
***
*
‘‘‘

For IInchRange0,4):
For JInchRange1,i+1):
Print‘ ‘,End=‘‘)
for J in range (1,6- 2*i):
print (" *, end= ")
for J in range ( Span style= "COLOR: #0000ff" >1,i+1):
print (", end = Span style= "COLOR: #000080" >print ()


#练习八: Printing
‘‘‘
*
**
***
****
*****
‘‘‘

Range (0,5):
Range (0,i+1):
Print (' * ',end=')
Print ()


#练习九: Printing
‘‘‘
******
*****
****
***
**
*
‘‘‘

Range (0,5):
Range (0,5-i):
Print (' * ',end=')
Print ()


#练习十: Writing the Login interface
Basic requirements:
Let the user enter the user name password
Show welcome message after successful authentication
Exit the program after a three-time error

n=0
while n<< Span style= "COLOR: #0000ff" > 3:
Name=input (" input your Name: ')
Pwd=input ( if name== " Zuo ' and pwd== " 123 ':
print ( ' hello ')
else:
n+=1


#数据类型练习题:
#练习一: decimal number n=10
Turn binary
to octal
to hexadecimal

n=10
Print (bin (N))
Print (Oct (N))
Print (hex (N))

#练习二: Interacting with users, requiring users to enter age and salary, turn user input age into shaping, convert user-entered payroll to floating-point


#练习三:
User input user name, age, work, hobby, format output as follows (using%s and format two methods)
------------info of Alex Li-----------
Name:alex Li
Age:22
Job:teacher
Hobbie:girl
-------------End-----------------

#练习四:
s= ' Alex say hello '
Slicing out section say
Slice out two characters after the countdown

#练习五:
# Write a loop to let the user enter the age, if the input is empty, or not a number, re-enter

#练习六:
Use a list to simulate the process (queue) on the elevator
Loop to generate a list of 1000 values (queued)
Loop take this 1000 value (out of the queue)


Use a list to simulate the process of putting clothes in a box and then taking clothes (stacks)
Loop generates a list of 1000 values (into the stack)
Loop take this 1000 value (out of the stack)




#元组


#字典



#集合



#tuple和list互相转换


#练习七:
Dicta={' A ': 1, ' B ': 2, ' C ': 3, ' d ': ' Hello '}
dictb={' B ': 3, ' C ': 2, ' d ': ' World ', ' F ': 10}
#两字典相加, the values of the different keys remain, the same key corresponding to the value of the addition is retained, if the string is spliced (string concatenation ' hello ' + ' world ' HelloWorld ')
# {' A ': 1, ' B ': 5, ' C ': 5, ' d ': ' HelloWorld ', ' F ': 10}






Practice Eight:
A. Implement user input user name and password, when the user name is seven and the password is 123, the display login is successful, otherwise the login failed!

B. Implement user input user name and password, when the user name is seven and the password is 123, the display login is successful, otherwise the login fails, allow repeated input three times when failed

C. Implement user input user name and password, when the user name is seven or Alex and the password is 123, the display login is successful, otherwise the login fails, the failure allows repeated input three times




Practice IX:
Write code

A. Using a while loop to implement output 2-3+4-5+6...+100 and
B. Using the For loop and range for output 1-2+3-4+5-6...+99 and
C. Using a while loop to implement output 1,2,3,4,5 7,8,9 11,12
D. Using a while loop to implement all odd numbers in output 1-100
E. Using a while loop to implement all the even numbers in output 1-100

Practice Ten:
Name = "Alex"
A. Remove the space on either side of the value that corresponds to the name variable and enter the content to be removed
B. Determine if the value corresponding to the name variable starts with "Al" and outputs the result
C. Determine if the value corresponding to the name variable ends with "x" and outputs the result
D. Replace "L" in the value corresponding to the name variable with "P", and output the result
E. Splitting the value corresponding to the name variable according to "L" and outputting the result
F. What is the type of value that was obtained after the e-partition of the previous question?
G. Capitalize the value corresponding to the name variable and output the result
H. Lowercase the value corresponding to the name variable and output the result
I. Please output the 2nd character of the value corresponding to the name variable?
J. Please output the first 3 characters of the value corresponding to the name variable?
K. Please output the first 2 characters of the value corresponding to the name variable?
L. Please output the index where "E" is located in the value corresponding to the name variable.

Exercise 11:
Write code, such as the following list, as required to achieve each function
Li = [' Alex ', ' Eric ', ' Rain ', ' Eric ', ' Rain ']
A. Calculate the length of the list and output
B. Append the element "seven" to the list and output the added list
C. Insert the element "Tony" in the 1th position of the list and output the added list
D. Please modify the element in the 2nd position of the list to "Kelly" and output the modified list
E. Remove the Element "Eric" from the list and output the modified list
F. Delete the 2nd element in the list and output the value of the deleted element and the list after the element is deleted
G. Delete the 3rd element in the list and output the list after the element is deleted
H. Delete the 2nd to 4th element in the list and output the list after the element is deleted
I. Invert all the elements in the list and output the inverted list



#练习十二:
Remove the name from the list, age, year of birth, month, day
data=[' Alex ', 49,[1900,3,18]]


#练习十三:
Remove Duplicates
names=[' Egon ', ' Alex ', ' Egon ', ' Wupeiqi ']


#练习十四:
Remove duplicates and ensure that the list order is consistent with the original
names=[' Egon ', ' Alex ', ' Egon ', ' Wupeiqi ']


#练习十五:
Remove duplicates and ensure that the list order is consistent with the original
names=[[1,2],3,[1,2],4]


#练习十六:
Statistics s= ' Hello Alex Alex say hello SB sb ' number of each word



#练习十七: Dictionary nesting uses
#alex发表了朋友圈:
Alex_msg= ""
I want to kinky a little poem
Sing the praises of my deskmate
Her black hair.
It seems to have been fried chicken.
‘‘‘

#eogn发表了朋友圈:
Egon_msg= ""
There is always illiteracy and literature
‘‘‘


comments={
alex_msg:{
' Author ': ' Alex ',
' Comments ': [
(' Wupeiqi ', ' really silly than '),
(' hanyyyy ', ' really silly '),
(' Egon ', ' Ibid. ')
],
' Thumb_counts ': 3,
},
egon_msg:{
' Author ': ' Egon ',
' Comments ': [
(' Alex ', ' who says '),
(' hanyyyy ', ' You've been expelled '),
(' Wupeiqi ', ' good stimulation ')
],
' Thumb_counts ': 2,
},
}


Python Weekend jobs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.