python--Basic Exercises

Source: Internet
Author: User

1. Install Python,ipython,pycharm Pro version software on Linux computers;

2. Install the Python3 version on the Windows computer and configure the environment variables to ensure that the script runs in a DOS environment;

3. How many different ways to run Python under Linux, and analyze their pros and cons. And tell me which one you like best.

There are three kinds of methods: Python, Ipython, Vim *.py

Code comparison less like the second, more convenient; The code is more than the choice of a third

4. Write a script that uses the Print statement script to display your name, age, favorite color on the screen

And some things related to you (background, interests, hobbies, etc.);


5. Read the following Python script:

#!/usr/bin/env python

1 + 2 * 4

A) What do you think this script is for?

Calculate 1+2*4

b) What do you think the script will output?

No output

c) Enter the above code, save as a script, and then run it. Does it do the same as you expect? Why not?

Not the same, the script is not complete enough

D) What is the difference between executing this code separately and executing it in the interactive interpreter? Try it and write the results.

The interactive interpreter can calculate the result directly

e) How can you improve the script so that it works as you think?

6. Variable Assignment:

1). assignment statement x, y, z = 1, 2, 3 What values will be assigned in X, Y, z respectively?

2). What values do z, x, y = y, z, x, x, Y, z contain?

7. The identifier. Which of the following are the valid Python identifiers? If not, please explain why!

Int32 40XL $aving $ printf Print

_print This self __name__ 0x40l

BOOL True Big-westos 2HOT2LS type

Thisis thisisint R_u_ready Int True

If do counter-1 access _

Not legal: $aving $ counter-1

8. With a given value of cyclic and conditional judgment num, the user input uses the Raw_input () function to prompt the user to enter a number between 1 and 100, if the user enters a number equal to NUM, the display succeeds and exits. Otherwise, an error message is displayed and the user is prompted again to enter a value until the condition is met.

9. (If.. Elif. Elif. Else investigation, review of cyclic statements)

The program with the text menu writes a program with a text menu, with the following items

(1) Take five numbers and

(2) Take the average of five numbers

....

(X) exit. (Exit ())

The user makes a selection and then performs the corresponding function. The program ends when the user chooses to exit. The utility of this program is that users switch between functions without restarting your scripts over and over again.

10. There are 1, 2, 3, 4 digits, how many different and non-repeating numbers of three digits can be formed? How much are they?


python--Basic Exercises

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.