标签:eps before reg 二进制 clear int uri bug nta
Proficient in Python operators; Proficient in Python built-in functions; Understand the simplification of combinatorial number definition; Understand the errors and problems associated with floating point operations.
Before the experiment, we should be familiar with the relevant knowledge points, draw up the corresponding experimental operation steps, and make clear the experimental purpose and requirements. During the experiment, obey the arrangement of the experiment instructor, observe the rules and regulations of the laboratory, and take good care of the experimental equipment; After the completion of the experiment, write the experiment report carefully (all the source code is given in the experiment report).
Verification-Driven.
def cni(n,i): minNI=min(i,n-i) result=1 for j in range(0,minNI): result=result*(n-j)//(minNI-j) return result
5. Procedures in Chapter 2 of the book.
Code for question 1:
x=input(‘Please input:‘) num=list(map(int,str(x))) result=sum(num) print(result)
Code for question 2:
# 输入两个集合setA和setB,分别输出他们的交集,并集和差集 x=input(‘Please input:‘) setA=set(x); y=input(‘Please input:‘) setB=set(y); B=setA | setB J=setA & setB C=setA - setB print(‘A与B的并集:‘,B) print(‘A与B的交集:‘,J) print(‘A与B的差集:‘,C)
Code for question 3:
# 输入1个自然数,输出他的二、八、十六进制 x=input(‘Please input:‘) y=int(x) er=bin(y) ba=oct(y) sl=hex(y) print(‘二进制串:‘,er) print(‘八进制串:‘,ba) print(‘十六进制串:‘,sl)
Code for question 4:
def cni(n,i): minNI=min(i,n-i) x=1 y=1 for j in range(0,minNI): x=x*(n-j) y=y*(minNI-j) return int(x/y)
The second solution:
from fractions import Fraction def cni(n,i): minNI=min(i,n-i) result=Fraction(1,1) for j in range(0,minNI): x=Fraction((n-j),(minNI-j)) result=result*x return result
-------------------------To be continued-------------------------------------
标签:eps before reg 二进制 clear int uri bug nta
原文地址:https://www.cnblogs.com/jianle23/p/13717807.html