程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Basic python programming exercises

編輯:Python

1、 Random generation 5~15 Integer between , And find the sum of these two numbers 、 Bad 、 product 、 merchant 、 Idempotent operation

An important function of randomness is random, know random.randint(a,b) #,a,b Refers to the interval , This problem is solved .

2、 Enter a four digit integer , Output its reverse order number

This problem has two main points , One is four + Integers , The second is in reverse order

In reverse order, if you follow the common idea : One number, one number, and then sort , Because numbers can't be sliced , If we first convert a number into a string (str, A string can be a sequence , Can index 、 Slicing, etc. ), Reverse sort string and convert to integer type (int), It's a lot easier , Here are two ways to write :

3、 Randomly generate one 100 A list of integers , Out of order , Then find its maximum value 、 minimum value 、 and 、 Average

This question has three points :

One is to randomly generate a list : To introduce random, Here you need to pay attention to the concept of lists []

The second is to disrupt the order :shuffle( Disrupt the sequence locally )

Third, calculation : Need to introduce numpy,python Basic computing functions in

4、 Generate a 8 Bit random password , The requirement must contain uppercase 、 Lowercase and numbers

The difficulty of this problem is how to make sure that there is a capital letter 、 A lowercase letter 、 And number , We need to introduce string function

5、 From the text (speech.txt) Read text from , And count each word / The number of times words appear

The first speech.txt Put it in the file directory ( You can also put it elsewhere , Then use relative path or absolute path )

Here are three knowledge points :

 1) Read text , Flow operation , Remember to open it. , operation ( Read or write ), close ( Avoid memory impact )

 2) Count the number of words in the text

3) Count the words in the text , Need to introduce jieba

f.read(...) The writing of has included close

There is no need to traverse when counting words ( Although the underlying logic is the same ), Use the list to deduce the formula directly ( Also called grammar sugar )

6、 From file (scores.csv) Read scores in (1000 A student ,8 Course ), And count everyone 、 The highest score of each course 、 Lowest score 、 average 、 Total score

Students who do data analysis may be used to pandas To write , Here is also a demonstration .

use pandas Read out the data , Others follow numpy equally

I have been wondering whether there is a shortcut key to copy the current line to the next line , Who knows about it , Reply in the comment area ~

 

 


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved