Python Zero foundation to mastery :Python Basic —— First experience

One ,Python First experience

1.Hello Python I'm coming.
#coding=utf-8 # Please add code here to complete the output “Hello Python”, Pay attention to case sensitivity ! ###### Begin ######
print("Hello Python") ###### End ######
2. I want to see the world
#coding=utf-8 # Please add the code here , Complete the output as required ###### Begin ###### name=input(" Please enter a person's name :")
name2 = input(" Please enter the name of a country :") print(" The world is so big ,"+name+" Want to go "+name2+" have a look .") ###### End
######
3. learn from good examples Python
#coding=utf-8 # Please add the code here , Complete the output as required ###### Begin ###### name=input(" Enter name :")
print("{} classmate , learn from good examples Python, have boundless prospects !".format(name )) # Please complete the command line name1 = name[0:1]
print("{} Great Xia , learn from good examples Python, Make a big show !".format(name1)) # Please complete the command line name2 = name[1:]
print("{} brother , learn from good examples Python, everybody loves !".format(name2 )) # Please complete the command line ###### End ######
Two , Python Basic grammar for beginners

1. Lines and indents
# Function with error 1 def wrong1(): print("wrong1") print(" There is a bad indentation here ") # Function with error 2 def
wrong2(): print("wrong2") if False: print("") print("") # Function with error 3 def wrong3():
print("wrong3") print("hello world") # Here is the code to call the three functions # Don't modify it if __name__ ==
'__main__': wrong1() wrong2() wrong3()
2. Identifier and reserved word
import keyword if __name__ == '__main__': # error 1 str1 = "string" print(str1)
# error 2 r1024 = "1024" print(r1024) # error 3 float_1 = 1.024 print(float_1) # error 3
pFalse = "False" print(pFalse) # Output reserved keywords here import keyword print(keyword.kwlist)
print("end")
3. notes
if __name__ == '__main__': # Here is the code to modify print(1) # print(2) print(3) # print(4)
print(5) # print(6) print("hello world") """ print(" This should not be output ") """ # print(1) #
print(2) print(3) print(4)
4. Input and output
if __name__ == "__main__": # ********** Begin ********** # a = int(input()) b
= int(input()) print("%d + %d = %d" %(a,b,a+b)) print("%d - %d = %d"
%(a,b,a-b)) print("%d * %d = %d" %(a,b,a*b)) print("%d / %d = %f" %(a,b,a/b)) #
********** End ********** #
 

Python Zero foundation to mastery :Python Basic —— Basic data type

One ,Python Introduction to string processing

1. String splicing : Composition of names
#coding=utf-8 # Variables for storing last and first names first_name = input() last_name = input() #
Please add the string concatenation code below , Complete the corresponding functions # ********** Begin ********** # full_name = first_name +"
"+last_name print(full_name) # ********** End ********** #
2. Character conversion
#coding=utf-8 # Gets the source string to be processed source_string = input() # Please add the code for string conversion below #
********** Begin ********** # source_string1=source_string.strip()
transform_string=source_string1.title() print(transform_string)
lenth=len(transform_string) print(lenth) # ********** End ********** #
3. String search and replacement
# coding = utf-8 source_string = input() # Please add the code below # ********** Begin
********** # print(source_string.find('day'))
new_string=source_string.replace('day','time') print(new_string)
new_string2=new_string.split(' ') print(new_string2) # ********** End
********** #
Two ,Python Introduction to play list

1. Addition, deletion and modification of list elements : Changes in guest list
# coding=utf-8 # Create and initialize Guests list guests = [] while True: try: guest = input()
guests.append(guest) except: break # Please add code here , Yes guests List to insert , Delete and so on ###### Begin
###### lenth=len(guests) deleted_guest=guests.pop() print(deleted_guest)
guests.insert(2,deleted_guest) guests.pop(1) print(guests) ####### End #######
2. Sorting of list elements : Sort the guests
#coding=utf-8 # Create and initialize `source_list` list source_list = [] while True: try:
list_element = input() source_list.append(list_element) except: break #
Please add code here , Yes source_list Sort the list and print out the sorted list #********** Begin *********#
source_list.sort(reverse=False) print(source_list) #********** End **********#
3. List of values : Speak with numbers
#coding=utf-8 # Create and read in range The corresponding parameters of the function lower = int(input()) upper = int(input())
step = int(input()) # Please add code here , Realize the programming requirements ###### Begin ######
sourse_list=list(range(lower,upper,step)) lenth=len(sourse_list) print(lenth)
min_value=min(sourse_list) max_value=max(sourse_list)
print(max_value-min_value) ####### End #######
4. List slice : Your menu and mine
# coding=utf-8 # Create and initialize my_menu list my_menu = [] while True: try: food = input()
my_menu.append(food) except: break # Please add code here , Yes my_menu List for slicing operation ###### Begin
###### lenth=len(my_menu) list_slice=my_menu[:lenth:3] print(list_slice)
list_slice2=my_menu[-3:] print(list_slice2) ####### End #######
3.Python Tuples and dictionaries for beginners

1. Use of tuples : Is this menu modifiable ?
# coding=utf-8 # Create and initialize menu_list list menu_list = [] while True: try: food =
input() menu_list.append(food) except: break #
Please add code here , Yes menu_list Tuple conversion and tuple calculation are performed , And print the tuple and the element with the largest tuple ###### Begin ######
print(tuple(menu_list)) print(max(menu_list)) ####### End #######
2. Use of dictionaries : This menu can be modified
# coding=utf-8 # Create and initialize menu_dict Dictionaries menu_dict = {} while True: try: food =
input() price = int(input()) menu_dict[food]= price except: break
# Please add code here , Implementation of the menu_dict Add , lookup , Modification and other operations , And print out the corresponding value ###### Begin ######
menu_dict['lamb']=50; print(menu_dict['fish']) menu_dict['fish']=100 del
menu_dict['noodles'] print(menu_dict) ####### End #######
3. Traversal of dictionary : Display of dish name and price
# coding=utf-8 # Create and initialize menu_dict Dictionaries menu_dict = {} while True: try: food =
input() price = int(input()) menu_dict[food]= price except: break
# Please add code here , Implementation of the menu_dict And print out the key and value ###### Begin ###### for key in
menu_dict.keys(): print(key) for value in menu_dict.values(): print(value)
####### End #######
4. nesting - The menu is so informative
#coding=utf-8 # initialization menu1 Dictionaries , Enter the price of the two courses menu1 = {} menu1['fish']=int(input())
menu1['pork']=int(input()) #menu_total The list now contains only menu1 Dictionaries menu_total = [menu1] #
Please add code here , Realize the programming requirements #********** Begin *********# menu2={}
menu2['fish']=menu1['fish']*2 menu2['pork']=menu1['pork']*2
menu_total=[menu1,menu2] #********** End **********# # output menu_total list
print(menu_total)
 

Technology
©2019-2020 Toolsou All rights reserved,
html Writing about cherry trees , Writing about cherry trees It's unexpected Python Cherry tree (turtle The gorgeous style of Library ) Browser kernel ( understand )HashMap Explain in detail java Four functional interfaces ( a key , simple )os Simple use of module Some East 14 Pay change 16 salary , Sincerity or routine ?