The cow brush off net python problem summary

? 1.max = x> y x: y is not python syntax, which is particularly confusing; python ternary operator as follows:

a if x>y else b

2.random.random () generates a random float float between 0 and 1

3. Assuming may not consider a computer running resources (such as memory) restrictions, expected operating results are the following python3 code :()

import math
def sieve(size):
    sieve= [True] * size
    sieve[0] = False
    sieve[1] = False
    for i in range(2, int(math.sqrt(size)) + 1):
        k= i * 2
        while k < size:
           sieve[k] = False
           k += i
    return sum(1 for x in sieve if x)
print(sieve(10000000000))
This question is seeking the number of prime numbers between 0-100 million, first you have to read the code.
After read the code, you have written Meissel-Lehmer algorithm to quickly find the number of prime numbers from 0-100 million.
Upstairs say about prime numbers less than 100 million online Baidu, I do not have to Baidu. But we can remember this value
4. The following class definition, the following description is the error?
class A(object):
pass
class B(A):
pass
b = B()
isinstance (b, A) == True, isinstance (b, object) == True, issubclass (b, B) == True is right
issubclass (B, A) == True wrong
the isinstance () function to determine whether an object is a known type, similar to the type ().
issubclass () function for determining whether the parameter is a subclass of a type parameter.

The following procedure to calculate the area of ​​a triangle based on user input three side lengths a, b, c. Please indicate errors in the program :( provided a user input method, a correct formula for the area)

import math
a, b, c = raw_input ( "Enter a, b, c:") # Cause: do not allow similar a, b, c = input () statement, otherwise it will error: It can be entereda,b,c = input('enter a b c: ').split()
s = a + b + c
s = s / 2.0
area = sqrt (s * (sa) * (sb) * (sc)) # should be math.sqrt, 1 or above directly from math import sqrt⚠️❗️
print “The area is:”, area
python3.x, only input () function

input (): accept any type of input, the returned object type String

Guess you like

Origin www.cnblogs.com/zhaikunkun/p/12649834.html