When you use float
you operate using 64 bits:
M☉ = $(1.98847±0.00007)$ × $10^{30}$kg
mantissa: 198847, exponent: $10^{30}$
The point separating the fractional part from the integer part starts between the first and the second digit in this example. So, a number with exponent $10^{0}$ and mantissa 198847 would be 1.98847.
solar_mass = 1e-8
print(solar_mass==1.98947*10**30)
1e+308
1.989E30 == 1.989*10**30
(0.2+0.1) == (0.5-0.2)
print('Your number is {:50.25}!'.format(0.2+0.1))
print('{:.25}'.format(0.5-0.2))
print('{:.25}'.format(0.3))
(0.2+0.1),(0.5-0.2)
'{0:.50}'.format(0.1)
An illustration of how fractions work in binary: https://en.wikipedia.org/wiki/Hexadecimal
import math
math.floor(0.2),math.ceil(0.2)
math.pow(0.1,2)
from math import pi,e,sin
print("Pi number:",pi,"\nEuler's number:",e)
math.cos(pi/2)
sin(pi/2)
from math import *
print("Cosinus:",cos(0),"\nLog2:",log2(32),"\nSquare root:",sqrt(1024))
from decimal import Decimal
print(Decimal('0.2')+Decimal("0.1"))
print(Decimal(0.2)+Decimal("0.1"))
a = Decimal('0.2')
a + a # possible
a + 0.2 # unsupported
print(Decimal('0.1000')+Decimal('0.20000002')) # number
from decimal import getcontext
getcontext()
Decimal('0.154')+Decimal('0.14')
(Decimal('0.154')+Decimal('0.14')).quantize(Decimal("1.00"))
getcontext().prec = 2
Decimal('0.155')+Decimal('0.14')
from decimal import ROUND_CEILING,ROUND_DOWN, ROUND_HALF_EVEN
getcontext().prec = 3
b = Decimal('0.154')+Decimal('0.14')
b
b.quantize(Decimal('.00'), rounding=ROUND_DOWN)
b.quantize(Decimal('.00'), rounding=ROUND_CEILING)
b.quantize(Decimal('.00'), rounding=ROUND_HALF_EVEN)
from fractions import Fraction
from math import sqrt
?sqrt
print(Fraction(1,3))
print(Fraction(1,3) + Fraction(7,3))
print(Fraction(1,4) * Fraction(2,3))
print(Fraction(3,4) / 3)
print(Fraction(7,4) % 1)
print(Fraction(1,4) ** 2)
print(Fraction(pi), 884279719003555/281474976710656, pi)
print(Fraction(pi).limit_denominator(max_denominator=100), 311/99, pi)
Fraction(Decimal('0.1')+Decimal('0.2'))
from fractions import gcd
gcd(9, 3)
gcd(2, 3)
gcd(10, 5)
gcd(0, 0)
string_section = 'an_example_of_some_string'
string_section[0],string_section[-5]
string_section[:4],string_section[5:7],string_section[:]
string_section[0:10:1],string_section[::2],string_section[6:2:-2],string_section[2:6:-2]
print(string_section[0:10:1])
print('0123456789')
string_section[::-1]
string_methods = 'an_example_of_some_string_2'
string_methods. # [press tab]
string_methods.upper()
string_methods.count("e"),string_methods.count("q")
print(string_methods.find("s"),string_methods.rfind("s"),string_methods.find("qwerty"))
print(string_methods[14])
print(string_methods.rfind("o", 1, 11))
string_methods.replace('_','####')
string_methods.split("_")
inputs = "1 2 3 4"
inputs.split()
You can join a Zoom conference in two ways: by a link and by the ID.
A conference link, however, contains the ID in a specific format.
Write a program that gets a link to a Zoom conference and outputs the conference ID.
In this example there are always 9 numbers in the ID and they are split into three sections of 3 numbers each.
Example:
Input data: conference link
https://us04web.zoom.us/j/123456789?pwd=bkN3djZmYlZ5MStFMWdqdmphSGFVdz09
Output data: ID
123 456 789
The link is always in the format https://us04web.zoom.us/j/XXXXXXXXX?pwd=YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY, the only things that change are the ID and the password (including password's length). You don't have to process cases with incorrect links.
# textlink = input()
textlink = 'https://us04web.zoom.us/j/123456789/pwd=bkN3djZmYlZ5MStFMWdqdmphSGFVdz09'
# first_index =
# second_index =
# use methods "find" and "rfind" to find the indices of the start and the end of the ID in the string
Convert a link from the first format to the second one
https://drive.google.com/file/d/1kazyfB4JHoZSmczN-FBVXB4C8qN5b46G/view?usp=sharing:
https://drive.google.com/uc?export=download&id=1kazyfB4JHoZSmczN-FBVXB4C8qN5b46G