numbers

How do I write tests correctly using unittest?

*爱你&永不变心* 提交于 2019-12-02 09:46:43
I am trying to figure out how to write unit tests for functions that I have written in Python - here's the code written below: def num_buses(n): import math """ (int) -> int Precondition: n >= 0 Return the minimum number of buses required to transport n people. Each bus can hold 50 people. >>> num_buses(75) 2 """ bus = int() if(n>=0): bus = int(math.ceil(n/50.0)) return bus I am attempting to write test code but they are giving me fail results - here's code I started with: import a1 import unittest class TestNumBuses(unittest.TestCase): """ Test class for function a1.num_buses. """ def test

Weird output, when number starts with 0

有些话、适合烂在心里 提交于 2019-12-02 09:44:01
问题 1. script: $num = "00445790"; echo $num; returns: 00445790 2. script $num = 00445790; echo $num; returns: 2351 Can somebody explain why I get 2351 on the second script? 回答1: Integers that start with zero are consider octal. Because octal integers only use numbers from 0 to 8 everything from the 9 on are ignored. So 00445790 becomes 004457 which is 2351 in decimal. 来源: https://stackoverflow.com/questions/30629817/weird-output-when-number-starts-with-0

Why is Infinity × 0 = NaN?

故事扮演 提交于 2019-12-02 09:36:13
问题 IEEE 754 specifies the result of 1 / 0 as ∞ (Infinity). However, IEEE 754 then specifies the result of 0 × ∞ as NaN. This feels counter-intuitive : Why is 0 × ∞ not 0? We can think of 1 / 0 = ∞ as the limit of 1 / z as z tends to zero We can think of 0 × ∞ = 0 as the limit of 0 × z as z tends to ∞. Why does the IEEE standard follow intuition 1. but not 2.? 回答1: It is easier to understand the behavior of IEEE 754 floating point zeros and infinities if you do not think of them as being

Get number of images in Photos.app?

一笑奈何 提交于 2019-12-02 09:33:06
问题 I know it's possible to get the images in the Photos.app by using ALAssetsLibrary but how do I get the total number of photos in Photos.app? Pretty much I am trying to check the number of photos because I am getting the last image in the Photos.app with the code from this question: Get last image from Photos.app? So if there's 0 images on the device, it won't execute the code from the link above. Anyway how can I get this? Thanks! 回答1: With the new Photos framework, introduced in iOS 8, you

基础学习记录(5/17)——函数与Lambda表达式

风流意气都作罢 提交于 2019-12-02 09:19:23
基础学习记录(5/17)——函数与Lambda表达式 一、函数 1.函数定义 2.函数参数 二、lambad语句 一、函数 1.函数定义 创建函数用def语句,其格式为:def fun_name(par1,par2,…): 由def关键字,函数名和参数表组成 def 函数名(参数列表) 函数体 任何传入参数或者自变量必须放在圆括号中间 定义函数内容以冒号开始,注意缩进问题 return语句用于返回一个对象结果,当程序执行到函数的return语句时,就会将指定的值返回并结束函数,return后面的语句将不会执行 python可以没有返回值,可以有一个返回值,也可以有多个返回值,返回值的数据类型没有限制 def funXY ( x , y ) : x = 2 * x + y y = y * y return x , y x = 4 y = 6 print ( funXY ( x , y ) ) # 14 , 36 2.函数参数 python中的函数参数主要有3种形式 位置或关键字参数 位置或关键字参数是python默认的参数类型,函数的参数定义为该类参数后,可以通过位置参数,或者关键字参数的形式传递参数 def fun2 ( a , b , c ) : print ( a , b , c ) fun2 ( 1 , 2 , 3 ) # 可使用位置参数输出 1 , 2 , 3 fun2 (

Want to create serial numbers

落爺英雄遲暮 提交于 2019-12-02 08:54:05
I want to generate the serial no.s e.g. I have, NID ----- ABD90 BGJ89 HSA76 and I want, ID NID --------- 1 ABD90 2 BGJ89 3 HSA76 What code should I run for this outcome? Please help me. Since you tagged SAS, I'll answer with SAS. Based on your question, getting that result from that input would be as simple as this data result; ID=_N_; set input; run; or proc sql; select ID as monotonic() ,NID from input ; quit; In pure Oracle you would do this select rownum, NID from input However you might want to throw on ORDER BY in there because you'll likely get different results every time you run that.

What is the Small “e” in Scientific Notation / Double in Matlab

自闭症网瘾萝莉.ら 提交于 2019-12-02 08:43:10
问题 when I calculate a very small number, matlab gives 1.12345e-15 What is this? I can interpret it as 1.12345*10^(-15) or its 1.12345*e^(-15) I am in very hurry. Sorry for the stupid question. 回答1: e represents scientific notation as Rahul said but it is base 10, not base e. Run the following code to confirm. 1e1 It gives you ans = 10 回答2: e represents exponential. Its the scientific notation of writing numbers. The base is 10. For example: 1e2 =100 1e-2= 0.01 来源: https://stackoverflow.com

Is there a good python library that can turn numbers into their respective “symbols”? [closed]

只谈情不闲聊 提交于 2019-12-02 08:27:38
0 = 0 1 = 1 ... 9 = 9 10 = a 11 = b ... 35 = z 36 = A 37 = B ... 60 = Z 61 = 10 62 = 11 ... 70 = 19 71 = 1a 72 = 1b I don't know what this is called. Base something? All I want is a function that can convert the numbers into these, and these back to numbers. Is there an easy function that can do this? You may inherit numbers.Number: def baseN(base,alphabet='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'): class _baseN(numbers.Number): digits=alphabet[:base] def __init__(self,value): if isinstance(value,int): self.value=value if self.value==0: self.string='0' else: tmp=[abs

printing out prime numbers from array

可紊 提交于 2019-12-02 08:06:26
I'd like to print out all prime numbers from an array with method. I can do it with one int but don't know how to return certain numbers from array. Thanks for help! public static boolean isPrime(int [] tab) { boolean prime = true; for (int i = 3; i <= Math.sqrt(tab[i]); i += 2) if (tab[i] % i == 0) { prime = false; break; } for(int i=0; i<tab.length; i++) if (( tab[i]%2 !=0 && prime && tab[i] > 2) || tab[i] == 2) { return true; } else { return false; } //return prime; } thanks both of you. Seems like its solved: public static void isPrime(int[] tab) { for (int i = 0; i < tab.length; i++) { if

Java program that prints out numbers that are divisible by other numbers

守給你的承諾、 提交于 2019-12-02 08:00:31
I have a program that reads two real numbers and then it prints out all the numbers between these two, that are divisible by 2 or 3 or 5. The program works fine, but when a user enters two really large numbers (for example, 1122222123333 and 214123324434434) the program takes a very long time to calculate the result. I would like to somehow fix the program, so that even for large numbers the result would be printed out instantly. here is my code so far : import java.util.Scanner; public class Numbers { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long x = sc