Удалил Untitled.ipynb

This commit is contained in:
Sergey Lemeshevsky
2020-03-18 21:39:35 +03:00
parent 7dba740376
commit 6a3c918bdc
24 changed files with 4029 additions and 810 deletions

View File

@@ -0,0 +1,80 @@
# -*- coding: utf-8 -*-
def main():
maxwidth = 100
print_start()
count = 0
while True:
try:
line = input()
if count == 0:
color = "lightgreen"
elif count % 2:
color = "white"
else:
color = "lightyellow"
print_line(line, color, maxwidth)
count += 1
except EOFError:
break
print_end()
def print_start():
print("<table border='1'>")
def print_end():
print("</table>")
def print_line(line, color, maxwidth):
print("<tr bgcolor='{0}'>".format(color))
fields = extract_fields(line)
for field in fields:
if not field:
print("<td></td>")
else:
number = field.replace(",", "")
try:
x = float(number)
print("<td align='right'>{0:d}</td>".format(round(x)))
except ValueError:
field = field.title()
field = field.replace(" And ", " and ")
field = escape_html(field)
if len(field) <= maxwidth:
print("<td>{0}</td>".format(field))
else:
print("<td>{0:.{1}} ...</td>".format(field, maxwidth))
print("</tr>")
def extract_fields(line):
fields = []
field = ""
quote = None
for c in line:
if c in "\"'":
if quote is None: # начало строки в кавычках
quote = c
elif quote == c: # конец строки в кавычках
quote = None
else:
field += c
# другая кавычка внутри строки в кавычках
continue
if quote is None and c == ",": # end of a field
fields.append(field)
field = ""
else:
field += c
# добавить символ в поле
if field:
fields.append(field) # добавить последнее поле в список
return fields
def escape_html(text):
text = text.replace("&", "&amp;")
text = text.replace("<", "&lt;")
text = text.replace(">", "&gt;")
return text
main()

View File

@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
import sys
import unicodedata
def print_unicode_table(word):
print("decimal hex chr {0:^40}".format("name"))
print("------- ----- --- {0:-<40}".format(""))
code = ord(" ")
end = sys.maxunicode
while code < end:
c = chr(code)
name = unicodedata.name(c, "*** unknown ***")
if word is None or word in name.lower():
print("{0:7} {0:5X} {0:^3c} {1}".format(code, name.title()))
code += 1
# End print_unicode_table
# Start main script
word = None
if len(sys.argv) > 1:
if sys.argv[1] in ("-h", "--help"):
print("usage: {0} [string]".format(sys.argv[0]))
word = 0
else:
word = sys.argv[1].lower()
if word != 0:
print_unicode_table(word)
#End main script

View File

@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
import cmath
import math
import sys
# Start get_float
def get_float(msg, allow_zero):
x = None
while x is None:
try:
x = float(input(msg))
if not allow_zero and abs(x) < sys.float_info.epsilon:
print("zero is not allowed")
x = None
except ValueError as err:
print(err)
return x
# End get_float
# Start 1st block
print("ax\N{SUPERSCRIPT TWO} + bx + c = 0")
a = get_float("enter a: ", False)
b = get_float("enter b: ", False)
c = get_float("enter c: ", False)
# End 1st block
# Start 2d block
x1 = None
x2 = None
discriminant = (b ** 2) - (4 * a * c)
if discriminant == 0:
x1 = -(b / (2 * a))
else:
if discriminant > 0:
root = math.sqrt(discriminant)
else: # discriminant < 0
root = cmath.sqrt(discriminant)
x1 = (-b + root) / (2 * a)
x2 = (-b - root) / (2 * a)
# End 2d block
# Start 3d block
equation = ("{0}x\N{SUPERSCRIPT TWO} + {1}x + {2} = 0"
" \N{RIGHTWARDS ARROW} x = {3}").format(a, b, c, x1)
if x2 is not None:
equation += " or x = {0}".format(x2)
print(equation)
# End 3d block

View File

@@ -76,5 +76,4 @@ def escape_html(text):
text = text.replace(">", "&gt;")
return text
main()

View File

@@ -37,8 +37,8 @@ else:
root = math.sqrt(discriminant)
else: # discriminant < 0
root = cmath.sqrt(discriminant)
x1 = (-b + root) / (2 * a)
x2 = (-b - root) / (2 * a)
x1 = (-b + root) / (2 * a)
x2 = (-b - root) / (2 * a)
# End 2d block
# Start 3d block