Python Exercise 2

Source: Internet
Author: User

Question:
1. Write out several branch structures in Python and explain their execution process;

(1) if:
If expression: #条件
Statement #输出


(2) If...else ...
If expression: #条件

Statement #输出
else: #其他条件
Statement #其他输出


(3) If...elif...else ...
If expression: #条件1
Statement #输出1

Elif expression: #条件2

Statement #输出2

Else

Statement #其他输出



2. Write out several loop structures in Python and explain their execution process;


(1) For loop
For I in Range (m.n,x):
The Loop statement #条件

Statement #输出


(2) While loop
While expression (or True,false):
The Loop statement #条件
Statement #输出


(2) while ... else .....
While expression:
Loop Statement #条件1

Statement #输出1

Else

Statement #输出2




3. Do you support switch statements in Python?
If supported, write out the statement format;
If not, say how python can achieve the same functionality;


In Python does not support switch statements, if you want to achieve the effect of switch, is to use if...elif...elif...else ... Statement


Programming Exercises:

1. The user enters a number to determine whether it is prime;

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/03/CC/wKiom1mgL4Dg2HJcAACA8y-h1IM457.png "title=" Screenshot from 2017-08-25 22-08-43.png "alt=" Wkiom1mgl4dg2hjcaaca8y-h1im457.png "/>


2. Write a Python script to determine if the variable name entered by the user is legal?
(The first letter or underscore, the others are numbers, letters or underscores)

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/A2/7C/wKioL1mgM6qDeyUvAABwg-wXDqs647.png "title=" Screenshot from 2017-08-25 22-26-41.png "alt=" Wkiol1mgm6qdeyuvaabwg-wxdqs647.png "/>











Python Exercise 2

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.