Take a Break & rename files & Draw Turtle (Ucity_python)

Source: Internet
Author: User

Ucity's Python tutorial learned a few small projects, now summarize and post the code.

There are two good ways to learn Python: one is to find modules, functions, and methods of use through official documents, and one is how a Google method is implemented, such as searching for "open web in Python" and choosing the answer to the stack overflow.

 

  1.take a break

Requirements: Set to a certain time, jump to a webpage, let the person in front of the computer rest

Steps: (1) The calculation time triggers the open page, (2) opens a specific webpage, (3) counts and loops.

ImportTime#Import Time ModuleImportWebBrowser#Importing Web ModulesTotal_breaks=3#Rest 3 timesBreak_count=0#recorded a few breaks.Print('The time is :'+time.ctime ())#the current time of the output while(Break_count<total_breaks):#number of cycles of restTime.sleep (2)#2 seconds from current timerWebbrowser.open ('https://weibo.com/')#open a Web pageBreak_count+=1#The current is the first few times to rest    Print(' the'+str (Break_count) +' Time')#output, which is the first few times of rest

 

2.rename_files

Requirements: Rename the image, remove the number

Step: (1) Get the picture name, (2) rename each picture.

ImportOs#Input ModuledefRename_files ():#Defining Functions    #(1) Get file names from a folder Step 1: Get file nameFile_list=os.listdir (R'E:\spyder\a\prank')#get a list of all files    Print(file_list)#View these listsSAVED_PATH=OS.GETCWD ()#Get Path    Print('the current working directory is:'+saved_path)#Current working directory is XX (not the directory where the picture is located)Os.chdir (R'E:\spyder\a\prank')#change to the working directory where the picture is located    #(2) for each file,rename filename Step 2: rename     forfile_nameinchFile_list:#cycle, change the name of the picture individuallyFile_name_new=file_name.translate (Str.maketrans ("',"','0123456789'))#Get rid of numbers        Print('Old name-'+file_name)#Output old name        Print('New name-'+file_name_new)#Output New nameOs.rename (file_name,file_name_new)#Replace nameOs.chdir (Saved_path)#change to the previous working directoryRename_files ()#calling Functions

3.draw Turtle

Requirements: Design Turtle motion Trajectory

Steps: (1) Design motion trajectory, (2) Design movement image

ImportTurtle as C#Input ModuledefDraw_square (Some_turtle):#Draw a rectangle     forIinchRange (1,5): Some_turtle.forward (100) Some_turtle.right (90)        defDraw_art ():#Draw This functionwindow=C.screen () Window.bgcolor (' White') Brad=C.turtle () brad.shape ('Turtle') Brad.color ('Yellow') Draw_square (Brad) Angie=C.turtle () angie.shape ('Arrow') Angie.color ('Blue') angie.circle (100) Window.exitonclick () Draw_art ()

* Do not know why, run the second time, will be error "kernel hangs, restart in."

Take a Break & rename files & Draw Turtle (Ucity_python)

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.