码迷,mamicode.com
首页 > 其他好文 > 详细

Experiment 1

时间:2020-09-24 21:13:35      阅读:35      评论:0      收藏:0      [点我收藏+]

标签:eps   before   reg   二进制   clear   int   uri   bug   nta   

Experimental Objective:

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.

Experimental Requirements:

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).

Experimental:

Verification-Driven.

Experimental Content:

  1.  Write a program, input any large natural number, output the sum of each number.
  2.  Write a program, input two sets seta and setb, respectively output their intersection, union and difference set.
  3.  Write a program, input a natural number, output its binary, octal, hexadecimal representation.
  4.  Read and debug the following code, analyze the code function, find and solve the errors in the code:
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.

Experimental steps:

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-------------------------------------

 

Experiment 1

标签:eps   before   reg   二进制   clear   int   uri   bug   nta   

原文地址:https://www.cnblogs.com/jianle23/p/13717807.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!