python tutorial with exercises

Read about python tutorial with exercises, The latest news, videos, and discussion topics about python tutorial with exercises from alibabacloud.com

Python Basics Exercises Pat Water problem (iii)

#学习笔记#用以练习python基础#Original title Link: https://www.patest.cn/contests/pat-b-practise/10391039. Buy or not buy (20)Little Red want to buy some beads to make a string of their favorite beads. The owner of the bead sells a lot of colorful beads, but refuses to sell any strings. So little Red want you to help judge, whether a bead contains all the beads they want? If so, tell her how many extra beads there are, and if not, tell her how many beads are mis

Python exercises 3--for

title: an Integer, which plus 100 is a complete square number, plus 168 is a complete square number, what is the number?Program Analysis:Assume that the number is X.1, then: x + + = n2, X + + 168 = m22. Calculation equation: m2-n2 = (M + N) (m-n) = 1683, set: M + n = i,m-n = J,i * J =168,i and J at least one is an even number4. Available: M = (i + j)/2, n = (i-j)/2,i and J are either even or odd.5, from 3 and 4 derivation can be known, I and J are greater than or equal to 2 even.6, because I * j

Python Exercises 2 optimization 1

: Years2=365month_days[1]=28lis.append (YEAR2) forI,jinchEnumerate (month_days):ifRemain2]): Month2=i+1lis.append (month2) day2=remain2-sum (month_days[:i]) lis.append (day2) Break Printtype (LIS)PrintLisPrint "%d days after the date is: %d%d months%d"% (num,lis[0],lis[1],lis[2]) Else:#when NUM is negativelis=[] remindays=0 years2=years1 year2=year1ifsumdays0:remindays=ABS (sumdays) whileremindays>=0:year2=year2-1ifyear2%4==0:remindays=remindays-366Else: Remindays=remindays-365lis.

Python core programming chapter seventh exercises

7-9. Translation(a) writing a character translation program (functionally similar to the TR command in Unix). We call this function tr (), which hasThree string parameters: source string, Destination string, basic string, syntax is defined as follows:def tr (Srcstr, DSTSTR, String)The content of Srcstr is the character set that you intend to "translate", Dsrstr is the character set that is obtained after translation, and string isThe string to which you intend to perform the translation operatio

Python Basics Exercises

Simple input-output interaction.A=input (" Please enter name:") b=input (" Please enter phone:") Print(" Please confirm your message:", A, b) the user enters two numbers and calculates and outputs two numbers of the sum: (try to do this with just one line of code) A=input ( " Please enter a number " ) b =input ( " Please enter the second number " ) sum =float (a) +float (b) print (" Two of the sum of:%.2f %sum) Enter a radius to calculate the area of the circle.p=3.14a=i

"Python exercises" independent of the small easy

Xiao Yi in order to show his parents he has grown up independent, he decided to move out to live for some time. A person's life adds a lot of expense: small easy to eat one fruit every day and need to pay X yuan of house rent every day. The current small hands have already had F fruit and d yuan money, small easy also can go to shop to buy some fruit, store each fruit sells p yuan. Small easy to express his ability to live independently, hope to live independently of the longer the better, small

Python Basics Exercises

1. Simple input/output interaction.>> film=input (' Please enter movie name ') Enter the movie name Battle Wolf print(film) battle Wolf2. The user enters two numbers, calculates and outputs the sum of two digits: (try to do this with just one line of code)Print (' sum of two numbers:', float (input (' Enter first number:') ") +float (Input (' Enter a second number: ' )) Enter the first number: input Second number:3453. Enter the radius to calculate the area of the circle# Enter the radius of the

Python Basics Exercises

1.Name=input (' Pleaseinput:')print('%s 'is the host. '%name)Please INPUT:PDDPDD is the host.2.Print (' two and s:%.2f'% (float (input (' Enter first value:') ') +float (input ( ' Please enter a second value: ')))Please enter the first value: 2 Please enter the second value:5 Two number of sum S:7.003.# assuming that the radius of the circle is Rr=input (' Please enter the radius of the circle r=')# assume that pi ispi π=input ( ' please input pi π= ' )# The area of the circle is Ss=float (R) **

Python Basics Exercises

1. Simple input/output interaction#输入 >>> name=" pig "print("hello,%s. "%name") #输出Hello, Pig.2. The user enters two numbers, calculates and outputs the sum of two digits: (try to do this with just one line of code)#输入数字M=input ("Please enter first number:")N=input ("Please enter a second number:")#求和公式Sum=int (m) +int (n)#结果Print ("Sum of two numbers:%.2f"%sum)One line of codePrint ("Sum of two numbers:%.2f"% (int (input ("first number:")) +int (Input ("second number:")))3. Enter a radius to ca

Python Basics Exercises

1. Simple input/output interaction.Name=input (" Please enter a name:")print(name)2. The user enters two numbers, calculates and outputs the sum of two digits: (try to do this with just one line of code)# user input number a = input (' Enter first number:'= input (' Enter second number:') )# sum sum=int (a) +int (b)# Show calculation results Print (" two numbers added to:", Int (a) +int (b))3. Enter a radius to calculate the area of the circle.# user Input number r=input (" Please enter radius:

Python Basics Exercises

1. Simple input/output interaction.>>> Name=input ('Please input:') Please input:22>>>Print(name)22>>> N=input (':'):23>>> name+N'2223'>>> Int (name) +int (n)45>>> name='Zhouy'>>>Print('hi,%s.'%name) Hi,zhouy.>>>2. The user enters two numbers, calculates and outputs the sum of two digits: (try to do this with just one line of code)# The user enters the number a=input (' Please enter the first number:') b=input (' Please enter a second number: ' )# summation sum=float (a) +float (b)# Show calcula

Basic Python exercises.

1, simple input/output interactionEnter a namename =input (' Please enter name:') Enter number=input (' Please enter your school number:') output name and school number print(' Please confirm your name and study number:' Name,number)2, the user enters two numbers, calculates and outputs the sum of two numbers: (try to do this with just one line of code)Enter the number x=input (' Please enter the first number:') y=input (' Please enter the second number:') Sum sum=float (x) +float (y) Displ

Python Basics Exercises

1. Simple input/output interaction.Print ('Hello world! ' ) Hello world! >>> input ('pleaseinput:') input:hi! ' hi! '2. The user enters two numbers, calculates and outputs the sum of two numbers: (and try to do this with just one line of code)P=input (' Please enter first number:') q=input (' Please enter the second number:') sum =int (p) +int (q)print(' two digit sum:%.2f'%sum) Please enter the first number: 3 Please enter the second number:5 two number of sum:8.003. Enter a radius to calculate

Python input IP address and mask tells you all the addresses that the network segment contains (IPY module exercises)

is realized by self-invocation to the correct network bit . -b = (A.split ('/') [0]). Split ('.') -A = B[0] +'.'+ b[1] +'.'+ b[2] +'.'+ str (int (b[-1])-1) +'/'+ A.split ('/') [-1] - Ipip (a) in - defMain (): to #The IP address and mask you need to know to enter the keyboard when executing the file +Inputip = Raw_input ('Please input IPaddress (example:192.168.1.1/24): \ n >>>') - Ipip (Inputip) the #ipip (' 10.10.10.1/30 ') #测试用例, in order to avoid repeated input comment off the above

Python Basics Exercises

Problem:1. Simple input/output interaction.2. The user enters two numbers, calculates and outputs the sum of two digits: (try to do this with just one line of code)3. Enter the radius to calculate the area of the circleFirst, simple input/output interaction:The second question, the sum of the output two numbersTo implement with one line of code, you can use thePrint (' Sum of two numbers:%s '% (float (input (' Enter the first number: ') +float (Input (' Enter the second number: ')))In the third

Python Basic Grammar Exercises

1. Print 99 multiplication table # Only print results for I in range (1,10): A for J in range (1,i+1): Print (i*j,end= "") print () #打印算数表达式for I in range ( 1,10): For J in Range (1,i+1): Print ("{0}*{1} = {2:2}". Format (j,i,i*j), end= "") print () 1*1 = 1 1*2 = 2 2*2 = 4 1*3 = 3 2*3 = 6 3*3 = 9 1*4 = 4 2*4 = 8 3*4 = 12 4*4 = 16 1*5 = 5 2*5 = 10 3*5 = 15 4*5 = 20 5*5 = 25 1*6 = 6 2*6 = 12 3*6 = 18 4*6 = 24 5*6 = 30 6*6 = 36 1*7 = 7 2*7 = 14 3*7 = 21 4*7 = 28 5*7 = 35 6* 7 = 42 7*7 = 49 1*8 =

Python exercises (eight) to find a prime number within 100,000

Optimization points:Even numbers must not be primes, because they can all be divisible by 2.The boundary of J can be taken as the root, because if a number can be divisible, the square root of it can be judged whether it is a prime value.Import Datetimestart = Datetime.datetime.now () #0.512,993 sec Print (2, end= ") for I in range (3, 100000, 2): for J in range (3, int (i * * 0.5) + 1, 2): # for J in range (3, I, 2): If I% j = 0:break Else:pass Print (i) print () end = (Datetime.datetime.now ()

Python applet exercises (7) September 28, 2017---Tell yourself how to practice, not to dream.

first day. N=1 for in range (5,0,-1= (n+1) print(n)6, Healthy recipes output. List of 5 different ingredients, please print out what they may consist of There is a dish name. Diet = ['Tomato','Broccoli','Cucumber','Steak','Shrimp'] forXinchRange (0,5): forYinchRange (0,5):if not(x==y):Print("{}{}". Format (Diet[x],diet[y]))7. The drawing of the pentagram. draw a red pentagram graphic. from Import*fillcolor ("red") Begin_fill () while True: Forward (+) Right (144) if abs (POS ()) :

Python Basics Exercises

1. Use while loop input 1 2 3 4 5 6 8 9Count = 1while count2. For all numbers of 1-100 Counts = 1num = 0while counts   3 . All odd numbers in output 1-100 Counte = 1while Counte   4 . All even numbers in output 1-100 Counte = 1while Counte   5, Beg 1-2+3-4+5 ... 99 of all numbers of the and Counte = 1num = 0num1 = 0while Counte   6. User Login (three chance retry)Count = 0while count  Python Basics Exercises

Python exercises Three Way

Params.items (): # definition All parameters if K not in params_dict:params_dict[k] = V.default Key = tuple (sorted (Params_dict.items ())) # Determine if you need to cache print (key) if key not in Local_cach E.keys (): Local_cache[key] = fn (*args,**kwargs), Datetime.datetime.now (). Timestamp () Return Local_cache[key] Return wrapper@mag_cachedef Add (x=4,y=5): Time.sleep (3) return x+yCommand Dispatcher程序员可以方便的注册函数到某一个命令,用户输入命令时,路由到注册的函数如果此命令没有对应的注册函数,执行默认函数用户输

Total Pages: 15 1 .... 6 7 8 9 10 .... 15 Go to: Go

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.