#Pick 4 '''. Raise the number by the power of 0.5.''' #Square Root def sqrt(num): sqrt= num**(0.5) return sqrt print (sqrt(64)) print (sqrt(2016)) print (sqrt(9)) print (sqrt(15665)) '''1. Find the highest decimal value,v, from the given number, x, that is less than or equal to the given number, using the following list: (v)(n) 1 I 4 IV 5 V 9 IX 10 X 40 XL 50 L 90 XC 100 C 400 CD 500 D 900 CM 1000 M 2. Convert v to its corresponding Roman numeral, n. 3. Subtract v from x. 4. Then repeat steps 1-3 until x is 0.''' #Decimal Number to Roman Numeral convert = [(1000,'M'),(900,'CM'),(500,'D'),(400,'CD'),(100,'C'),(90,'XC'),(50,'L'),(40,'XL'),(10,'X'),(9,'IX'),(5,'V'),(4,'IV'),(1,'I')] def num2rom(num): rom='' while num>0: for i,r in convert: while num >= i: rom = rom + r num = num - i return rom print (num2rom(64)) print (num2rom(2016)) print (num2rom(9)) print (num2rom(1565)) # To determine the prime factors of a number make a list of the first prime numbers and try them to see if # they are divisors of the original number. If it is then save it as a prime factor prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199] def prime_factors(n): i = 2 factors = [] while i*i <= n: if n % i: i += 1 else: n //= i factors.append(i) if n > 1: factors.append(n) return factors print (prime_factors(27)) print (prime_factors(64)) print (prime_factors(121)) print (prime_factors(2925)) def dec2bin(x): return dec2bin(x/2) + [x%2] if x > 1 else [x] print (dec2bin(48564)) print (dec2bin(558845345)) print (dec2bin(11565))
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question