Gribouillis 1,391 Programming Explorer Team Colleague

I think your data is not valid python code. For example to read the hindi part, I had to replace all the \N with \ \N (double backslash) otherwise python would not read the unicode string.

Here is what I get when I print the hindi part:

ताजा\JJ साँसें\N_NN और\CC_CCD चमचमाते\JJ दाँत\N_NN आपके\PR_PRP व्यक्तित्व\N_NN को\PSP निखारते\V_VM हैं\V_VAUX ।\R

does it have something to do with what you want ?

Your question doesn't mean much. The unicode does not have to be converted to the target language. It is already in that language. What you want is probably to display the unicode with the language's human glyphs, which is something else. For this, the print function should work, for example I don't know hindi but

>>> y = u'\u0924\u093e\u091c\u093e'
>>> print(y)
ताजा
>>> 

It would be great if you could attach a small file to a post containing your exact data (for example a csv file in UTF8. You can zip the file to attach it to a post).

Edit: it's too bad, we still have this bug with the unicode characters in the forum!

Gribouillis 1,391 Programming Explorer Team Colleague

Here is a python program with almost the same statements

from os import fork, getpid
from sys import exit

def main():
    i = 2
    while i <= 4:
        print('PID', getpid(), ': Hello', i)
        if (i & 1) and (fork() == 0):
            print('PID', getpid(), ': OS', i)
            fork()
            if fork() > 0:
                exit(1)
            print('PID', getpid(), ': Students', i)
        else:
            print('PID', getpid(), ': World', i)
        i += 1
    return 0

if __name__ == '__main__':
    exit(main())

""" my output -->
('PID', 7621, ': Hello', 2)
('PID', 7621, ': World', 2)
('PID', 7621, ': Hello', 3)
('PID', 7621, ': World', 3)
('PID', 7621, ': Hello', 4)
('PID', 7621, ': World', 4)
('PID', 7622, ': OS', 3)
('PID', 7625, ': Students', 3)
('PID', 7625, ': Hello', 4)
('PID', 7625, ': World', 4)
('PID', 7624, ': Students', 3)
('PID', 7624, ': Hello', 4)
('PID', 7624, ': World', 4)
"""

A is 7621, the child B is 7622, the grandchild and grandgrandchild are 7624 and 7625 (which is which ?)

Gribouillis 1,391 Programming Explorer Team Colleague

The expression i & 1 is true only if i is odd. This will happen only if i equals 3 in the loop. In that case fork() is executed and creates a child process. Let A be the main process and B the child process created at this moment. The if statement's body is only executed in process B (because that's where fork() returned 0). Then, the fork() at line 14 is executed, spawning a grandchild process say C. Line 15 is executed in both B and C, spawning another grandchild D and a grandgrandchild E. B and C exit at line 16 with status 1 while D and E both print Students and go to next loop with i == 4.

Gribouillis 1,391 Programming Explorer Team Colleague

You don't need a terminal if you burn the disk from here http://sourceforge.net/projects/boot-repair-cd/files/

Gribouillis 1,391 Programming Explorer Team Colleague

Your method can be called optimization by scanning. It has the advantage of requiring nothing but elementary python code to work. In applications, one would use an existing solver such as solvers found in scipy. For example

>>> from scipy import pi
>>> import scipy.optimize as opt
>>> 
>>> def objective(r, vol):
...     return 2 * (pi * r**2) + (2 * pi * r * vol/(pi * r**2))
... 
>>> result = opt.minimize_scalar(objective, args = (500,), bracket = (0.0001, 10000.0))
>>> print(result)
  fun: 348.73420545288792
 nfev: 27
  nit: 26
    x: 4.3012700752223054
>>> 

The scipy solvers contain powerful methods of numerical analysis. They can save a lot of programmer's time in many common math problems such as minimization or root finding.

Gribouillis 1,391 Programming Explorer Team Colleague

We don't know what n is. The easiest way is to make it an attribute of a TheShuttles instance.

class TheShuttles:
    def __init__(self):
        self.n = 0

    def getLeastCost(self, baseCost, seatCost, cnt):
        def cost(x):
            self.n = sum(m / x + (m % x != 0 ) for m in cnt)
            return self.n * (baseCost + x * seatCost)
        return min(cost(x) for x in range(1, 101))

Also, the cost function could be a method of class TheShuttle instead of a function inside a function, it would be easier to understand. Type import this in a python console for good advice.

Configure your code editor to indent python code with 4 spaces, and read PEP8 for help on coding style.

EDIT: In python 2, make sure to declare a superclass, use object if necessary:

class TheShuttles(object):
    ...

In python 3, this is not needed. If you are new to python, start with python 3.

Gribouillis 1,391 Programming Explorer Team Colleague

The if condition looks if the dictionary tm contains a key which is a tuple of length 1 containing the word as sole item. If it does not, a value is associated to this key in this dictionary.

It seems strange to me that you don't work with unicode strings instead of utf8-encoded strings. For exemple in python 2:

>>> s = 'pass\xc3\xa9'
>>> t = s.decode('utf8')
>>> print(t)
passé
>>> print(repr(t))
u'pass\xe9'
Gribouillis 1,391 Programming Explorer Team Colleague

It is not the right output. Consider the following example

>>> from binascii import unhexlify
>>> s = "f0"
>>> A = unhexlify(s)
>>> B = r"\x" + r"\x".join(s[n : n+2] for n in range(0, len(s), 2))
>>> print(A)
�
>>> print(B)
\xf0
>>> print(repr(A))
'\xf0'
>>> print(repr(B))
'\\xf0'
>>> print(len(A))
1
>>> print(len(B))
4

The string A constructed with unhexlify() contains a single byte, which is '\xf0', or the 8 bits 11110000 (it does not print well in a terminal because it is not a printable character). String B constructed with vegaseat's expression contains 4 bytes, namely the characters \, x, f, 0. Its bitwise representation is 01011100011110000110011000110000.

See this post https://www.daniweb.com/software-development/python/code/221031/string-to-bits#post1484218 for bit representations of byte strings.

Edit: are you the blog's author ?

Gribouillis 1,391 Programming Explorer Team Colleague

Vegaseat's method does not work. It gives another string:

  '\\xf0\\xcb\\xf2\\x60\\xe0\\xca\\x8e\\xc2\\x43\\x10\\x89\\xfb\\x39\\x3a\\x1c\\x29\\x51\\x3a\\xaa\\xa5\\x84\\x7d\\x13\\xe8\\xbe\\x84\\x76\\x09\\x68\\xe6\\x4d\\xc6'
Gribouillis 1,391 Programming Explorer Team Colleague

Sequences such as \xf0 represent a single byte (8 bits. Remark: in python 3, use b'\xf0').

Some bytes are better viewed as ascii characters. For example 'Q' and '\x51' are the same character. In fact, 'Q' is the character number 81 in ascii, and 81 rewritten in hexadecimal system is 51, (5*16 + 1). See https://en.wikipedia.org/wiki/ASCII .

Python displays printable characters in ascii form and other characters in hex form.

Edit: some special characters are escaped too, '\t' is a tabulation character (number 9, or '\x09').

Gribouillis 1,391 Programming Explorer Team Colleague

Hi. Use module binascii

>>> from binascii import unhexlify
>>> s = 'f0cbf260e0ca8ec2431089fb393a1c29513aaaa5847d13e8be84760968e64dc6'
>>> t = unhexlify(s)
>>> t
'\xf0\xcb\xf2`\xe0\xca\x8e\xc2C\x10\x89\xfb9:\x1c)Q:\xaa\xa5\x84}\x13\xe8\xbe\x84v\th\xe6M\xc6'
Gribouillis 1,391 Programming Explorer Team Colleague

Here is the basic idea

#!/usr/bin/env python
# -*-coding: utf8-*-
'''doc
'''
from __future__ import (absolute_import, division,
                        print_function, unicode_literals)

import numpy as np
from scipy.optimize import linprog

def main():
    point = np.array([0.8, 0.12, 0.4])
    n = len(point)
    N = 30
    a = np.random.rand(n, N)
    a = np.insert(a, n, 1.0, axis=0)
    b = np.append(point, 1.0).reshape(n+1,1)
    bounds = [(0.0, 1.0) for i in range(N)]
    c = np.zeros(N)
    c[0] = 1.0
    print(a)
    print(b)
    print(c)
    result = linprog(c, A_eq=a, b_eq=b, bounds=bounds)
    print(result)
    if result.status == 0:
        print('Point is in convex hull')
    else:
        print('Point is not in convex hull')

if __name__ == '__main__':
    main()

""" my output -->
17:31 2015-03-31] python convex.py
[[ 0.26366509  0.92411732  0.9081528   0.88461942  0.68029591  0.42997518
   0.17189674  0.07542255  0.6627228   0.46370079  0.29521928  0.50230071
   0.73392039  0.70076308  0.39031932  0.73670852  0.64815496  0.52975825
   0.78314098  0.60898234  0.63308929  0.32659967  0.02298467  0.17494737
   0.01397131  0.27248117  0.98193604  0.69879033  0.90454457  0.06127812]
 [ 0.16418386  0.05802131  0.07673203  0.50894301  0.45885838  0.13100915
   0.43334997  0.3613589   0.70104947  0.47547909  0.64204601  0.18567562
   0.07257718  0.49943999  0.96490179  0.16901995  0.14288372  0.55158995
   0.12849092  0.4287121   0.33522966  0.32258957  0.54137264  0.24533261
   0.26382428  0.35957173  0.45413843  0.96331716  0.41831803  0.34442463]
 [ 0.77288019  0.04946268  0.00280707  0.07217767  0.62230434  0.97351116
   0.78616099  0.74724063  0.35259706  0.82299753  0.8465832   0.7326628
   0.65494121  0.88904928  0.67263953  0.23434955  0.74143111  0.4536738
   0.81357322  0.7408426   0.52483849  0.44427614  0.75840825  0.04656877
   0.84187546  0.94461097  0.42198365  0.20315269  0.21713841  0.29179429]
 [ 1.          1.          1.          1.          1.          1.          1.
   1.          1.          1.          1.          1.          1.          1.
   1.          1.          1.          1.          1.          1.          1.
   1.          1.          1.          1.          1.          1.          1.
   1.          1.        ]]
[[ 0.8 ]
 [ 0.12]
 [ 0.4 ]
 [ 1.  ]]
[ 1.  0.  0.  0.  0. …
fatalaccidents commented: This is the basic logic that I used, although I used scipy.spatial.ConvexHull because my anaconda distribution doesn't seem to have linprog (?) +2
Gribouillis 1,391 Programming Explorer Team Colleague

You can use tuples of integers to store the dice results, for example

attacking_values = (random.randint(1,6), random.randint(1,6),)
Gribouillis 1,391 Programming Explorer Team Colleague

Replace phrase[0] with words[0].

Courtney_1 commented: Thanks! I can't believe I was making such a dumb mistake. +0
Gribouillis 1,391 Programming Explorer Team Colleague

You could use my snippet to restart the program https://www.daniweb.com/software-development/python/code/260268/restart-your-python-program- .

From action_reload(), you can call restart_program(). Before that, you can try to compile the main program in order to eliminate possible syntax errors.

Gribouillis 1,391 Programming Explorer Team Colleague

@Wojciech I think you have two options:

  • You can create Wojciechweb and program your own forum application the way it should be done,
  • OR you can convince Dani to hire you as a web programmer!
Gribouillis 1,391 Programming Explorer Team Colleague

Very good. It can be improved with n = len(mylist) % 4.

Gribouillis 1,391 Programming Explorer Team Colleague

Here is what you can do with an array for example

>>> from array import array
>>> spam = b'5470011234567000'
>>> eggs = array('b', spam)
>>> eggs
array('b', [53, 52, 55, 48, 48, 49, 49, 50, 51, 52, 53, 54, 55, 48, 48, 48])
>>> spam
b'5470011234567000'
>>> eggs[3] = 67
>>> eggs
array('b', [53, 52, 55, 67, 48, 49, 49, 50, 51, 52, 53, 54, 55, 48, 48, 48])
>>> bytes(eggs)
b'547C011234567000'
Gribouillis 1,391 Programming Explorer Team Colleague

Your python code does not look like the C code. At line 7 and 11, it should be m_key_code[idx] = .... Also 0 should probably be n0 at the end of line 7.

It means that m_key_code must be a writable structure such as a list or an array (in module array). What type did you choose for m_key_code ?

Edit: Sorry, I see from the log that m_key_code is a bytes. It won't work because a bytes is immutable.

Gribouillis 1,391 Programming Explorer Team Colleague

Yes {} does not have the same semantics in C or in python. Use lists [] or tuples () for the e_rotor*. Or you can probably use a bytes

e_rotor_10 = bytes([5, 4, 1, 8, 7, 3, 0, 2, 9, 6])
Gribouillis 1,391 Programming Explorer Team Colleague

Great, good luck!

Gribouillis 1,391 Programming Explorer Team Colleague

We still don't know if you are using python 3, nor the type of enigma_string, which is necessary here (print type(enigma_string)). Assuming this is python 3 and enigma_string is a bytes, you can try

    key_length = len(enigma_string)
    m_key_code = enigma_string
    n0, n9, nA = b'09A'


    check_sum = 1
    for idx, n in enumerate(m_key_code[2:], 2):
        if n0 <= n <= n9:
            temp_sum = n - n0
            print("DEBUG temp Sum", temp_sum)
        else:
            temp_sum = n - nA

        check_sum += idx + temp_sum + (idx * temp_sum)
        print("DEBUG> Check Sum:", check_sum)

    check_sum = 100 - (check_sum) % 100
    dummy = [n0 + (check_sum % 10), n0 + ((check_sum // 10) % 10)]
    m_key_code = bytes(dummy) + m_key_code[2:]
Gribouillis 1,391 Programming Explorer Team Colleague

It depends on what you call good. I have a Epson XP-700 at home and it works very well with linux kubuntu. Epson publishes free drivers for the printer and the scanner. Avoid certain brands such as Lexmark which have a tradition of poor linux support (it may have changed since I had this problem, but be very careful).

Gribouillis 1,391 Programming Explorer Team Colleague

If you want to start at position 2, you only need

for idx in range(2, key_length):

Do you have a variable m_keyCode ? The body of the for loop depends on this. If you are with python 3 and m_keyCode is a bytes instance, it is easy because the values are already small integers, for example

>>> v = b'4211'
>>> print([x for x in v])
[52, 50, 49, 49]

If you are with python 2, you'll have to use ord()

>>> v = '4211'
>>> print([ord(x) for x in v])
[52, 50, 49, 49]
Gribouillis 1,391 Programming Explorer Team Colleague

Why not try D ? It was originally a language for windows because its creator Walter Bright wrote the first DMD compiler for windows, but it now works on various platforms including linux, and there are QT bindings http://www.dsource.org/projects/qtd . D is a very attractive language.

Gribouillis 1,391 Programming Explorer Team Colleague

You'll need some time and more googling to get a correct picture of all these languages. For example fortran's domain is not OS programming but engineering and numerical analysis.

Wikipedia has a long list of programming languages https://en.wikipedia.org/wiki/List_of_programming_languages : you cannot reasonably learn all of them :)

The choice of the programming language is partly independent from the choice of the gui toolkit. For example you can code QT4 guis in many languages https://en.wikipedia.org/wiki/List_of_language_bindings_for_Qt_4 The same hold for Tcl/Tk or wxwidgets.

Gribouillis 1,391 Programming Explorer Team Colleague

I don't understand what q and g are in your code. If you want to add a number to every value in a list, you can do

mylist = [83, 111, 109]
offset = 22
mylist[:] = [value + offset for value in mylist]
# mylist is now [105, 133, 131]
Gribouillis 1,391 Programming Explorer Team Colleague

Version 0.2.0 is a minor bugfix for python >= 3.3!

Gribouillis 1,391 Programming Explorer Team Colleague

The first thing is to never have variable names containing a variable index, such as product_1, product_2, etc. Use lists or tuples instead

pairs = [
    ("Flake", 0.55), ("Wispa", 0.50),("Crunchie", 0.65),
    ("Milky Way", 0.35), ("Boost", 0.65)
]
product, product_price = zip(*pairs)

Then product[0] is 'Flake',product[4] is 'Boost' and similarly for product_price.

You can write loops

for i, p in enumerate(product):
    print('Item: {} Price: {}'.format(p, product_price[i]))
Basel_1 commented: Thanks man, this really helped. +0
Gribouillis 1,391 Programming Explorer Team Colleague

The history of the unix system is tightly bound to the history of the C programming language, so I would say that a genuine linux application is written in C, with the help of the GNU tools.

However, C is a little bit outdated, so I think C++ can be tolerated.

There is nothing in linux that plays the role of the .net framework in windows, so that most modern languages but microsoft's languages can be considered native in linux. For example a python program is very linuxish. It is sustained by libraries written in C and it gives you a complete access to CLI and GUI libraries.

RikTelner commented: "For example a Python program is very Linuxish" - noted. +2
Gribouillis 1,391 Programming Explorer Team Colleague

You can define a color with for example

fillcolor('green')

Then you can fill a domain with

fill(True)
#... Here draw a domain as you did before
fill(False)
Gribouillis 1,391 Programming Explorer Team Colleague

If you are working in number theory, you might be interested in the python interface to the PARI GP calculator system: pari-python. It contains many functions for number theory (it probably does not work with python 3 however)

BustACode commented: Thanks. +0
Gribouillis 1,391 Programming Explorer Team Colleague

Here is how you can code the same thing by using a PEP8 compliant coding style

# -*-coding: utf8-*-
# python 2 or 3

def get_middle_factors(factor_list):
    """Return a list of the term(s) in the middle of a list

    A list of length 1 or 2 is returned, depending on the
    length of the argument list being odd or even.

    Example:

        >>> get_middle_factors([1, 7, 13, 91])
        [7, 13]
        >>> get_middle_factors([1, 7, 91])
        [7]
    """
    n = len(factor_list)
    q, r = divmod(n-1, 2)
    return factor_list[q:q+1+r]

def main():
    print("Middle Factors: {}".format(get_middle_factors([1, 7, 13, 91])))
    print("Middle Factors: {}".format(get_middle_factors([1, 7, 49])))

if __name__ == '__main__':
    main()

""" my output -->
Middle Factors: [7, 13]
Middle Factors: [7]
"""

PEP 8 is good for your code as it makes it easier to read, especially by trained python programmers, who may not take the time to decrypt code written with a significantly different style.

Gribouillis 1,391 Programming Explorer Team Colleague

There is a better way: you can disable 2C when 1A is on. In the following code, I added a callback method, which is called when one of the options is selected. It is a very good way to prohibit some choices. It is completely configurable.
This code needs to be completed, I only started the refactoring, but it already works.
Compare it to your code with a diff visualizer such as meld or kdiff3 or winmerge, etc.

import Tkinter as tk
from Tkinter import *
from functools import partial


LARGE_FONT= ("Verdana", 12)

class ChangePages(tk.Tk):

    def __init__(self, *args, **kwargs):

        tk.Tk.__init__(self, *args, **kwargs)
        container = tk.Frame(self)
        container.pack()
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)
        self.frames = {}
        for F in (MainPage, Page01, Page02):

            frame = F(container, self)

            self.frames[F] = frame

            frame.grid(row=0, column=0, sticky="nsew")

        self.show_frame(MainPage)

    def show_frame(self, cont):

        frame = self.frames[cont]
        frame.tkraise()

#MainPage
class MainPage(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self,parent)

        button1=Button(self,text='Go To Page 1',fg='blue',font=('Helvetica',26),height=5, width=20,command=lambda: controller.show_frame(Page01)).grid(row=1,column=1)

#Page01
class Page01(tk.Frame):

    def __init__(self, parent, controller):

        self.option1 = option1 = IntVar()
        self.option2 = option2 = IntVar()
        self.option3 = option3 = IntVar()

        tk.Frame.__init__(self, parent)
        f = Frame(self)
        f.pack(side='left')

        label1=Label(f,text='Select options',fg='blue', font=("Arial", 36, "bold"),width=54, relief='solid').grid(row=1,column=1,columnspan=3)

        labelspacing=Label(f,text='Option 1 ',font=("Arial", 18, "bold"),width=20,height=1).grid(row=2,column=1)
        labelspacing=Label(f,text='Option 2 ',font=("Arial", 18, "bold"),width=20,height=1).grid(row=2,column=2)
        labelspacing=Label(f,text='Option 3',font=("Arial", 18, "bold"),width=20,height=1).grid(row=2,column=3)

        def C(*args): return partial(self.option_changed, *args)

        buttonoption11=Radiobutton(f, text="Option 1 - A", variable=option1, value=1, indicatoron=0, fg='blue',font=('Helvetica',26),height=1, width=20, command=C(1,'A')).grid(row=3,column=1)
        buttonoption21=Radiobutton(f, text="Option 2 - A", variable=option2, value=1, indicatoron=0, fg='blue',font=('Helvetica',26),height=1, width=20, command=C(2,'A')).grid(row=3,column=2)
        buttonoption31=Radiobutton(f, text="Option 3 - A", variable=option3, value=1, indicatoron=0, fg='blue',font=('Helvetica',26),height=1, width=20, command=C(3,'A')).grid(row=3,column=3)

        buttonoption12=Radiobutton(f, text="Option 1 - B", variable=option1, value=2, indicatoron=0, fg='blue',font=('Helvetica',26),height=1, width=20, command=C(1,'B')).grid(row=4,column=1) …
Gribouillis 1,391 Programming Explorer Team Colleague

You need to add the group number, for example

import datetime as dt
import itertools as itt
import operator as op

def todatetime(string):
    return dt.datetime.strptime(string, '%H:%M:%S')

def enhanced_sequence(seq):
    """yields pairs (group number, time string)

    Arguments:
        seq: sequence of ordered time string 'HH:MM:SS'
    """
    seq = iter(seq)
    prev = next(seq)
    dtprev = todatetime(prev)
    group = 0
    yield (group, prev)
    for s in seq:
        dts = todatetime(s)
        if (dts - dtprev).total_seconds()/60.0 >= 1
            group += 1
        yield (group, s)
        prev, dtprev = s, dts

def time_groups(seq):
    """Yield list of grouped time strings

    Arguments:
        seq: sequence of ordered time string 'HH:MM:SS'
    """
    for key, g in itt.groupby(enhanced_sequence(seq), key=op.itemgetter(0)):
        yield [x[1] for x in g]

Edit: bugfix

Gribouillis 1,391 Programming Explorer Team Colleague

Yes because Vegaseat uses

import tkinter as tk

while you are using

from tkinter import *

Usually, people prefer to avoid import * because there is no way to see which names are imported in the current namespace. With the first import, only the variable tk is added to the current namespace.

Avoiding import * is a good rule, although very good tkinter programs have been written with this import.

Gribouillis 1,391 Programming Explorer Team Colleague

I think the program should create a backup of itself before attempting to rewrite itself and restore the backup if anything goes wrong. It would be a minimal security feature if one wants to develop this.
IMHO, the main issue is that it is not very useful. A more standard procedure is that a program rewrites a configuration file and that this file is loaded when the program is executed. It is more robust, and it permits to reload the configuration file once it has been updated. Here reloading would mean restarting the program.

Gribouillis 1,391 Programming Explorer Team Colleague
Gribouillis 1,391 Programming Explorer Team Colleague

As there is no issue, you could post this as a code snippet (select the appropriate article type when the article is created). Why not add a call tomain() at the end so that it does something when we try it ?

BustACode commented: System won't let me post as "snippet," only discussion. +0
Gribouillis 1,391 Programming Explorer Team Colleague

You might be interested in my print_multicolumn() code snippet https://www.daniweb.com/software-development/python/code/468373/print-a-list-in-multicolumn-format and also by module prettytable in general. Here is what it does

>>> L = ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'bbbbbbbbbbbbbbbbbbb', 'c', 'k', 'k', 'l', 'a', 'b', 'c']
>>> print_multicolumn(L, 3, vertically=False)
  a   b                     c  
  a   b                     c  
  a   bbbbbbbbbbbbbbbbbbb   c  
  k   k                     l  
  a   b                     c 
Gribouillis 1,391 Programming Explorer Team Colleague

Standard builtin functions have been tested gazillion times by programs all around the world. It is almost impossible that you discover an unknown bug in them. strip() removes characters only at both ends of the string. You will have to use replace()

>>> 'qazxswedc'.replace('x', '')
'qazswedc'
Gribouillis 1,391 Programming Explorer Team Colleague

Python complains because the file's write() method needs a string argument. Here the correct way to handle things is to find the values of the href= attributes, which contain the link targets. If you want to write anything to the file, you can use write(str(anything)).

Gribouillis 1,391 Programming Explorer Team Colleague

You don't need to install it: it is part of the python standard library. Look in the standard's library documentation for reference.

Gribouillis 1,391 Programming Explorer Team Colleague

Yes , you mistakenly believe that the function equals 1. The square root is in fact sqrt((x-1)**2) Mathematically, it has the same value as abs(x-1), which is x-1 when x >= 1 and 1-x when x <= 1. It means that your function's value is x when x < 1.

Gribouillis 1,391 Programming Explorer Team Colleague

Hm, the RAR file contains two exe programs which are fired by the python program. It is probably a virus or spyware. The best thing to do is not to run this program. It could very well erase all your files for example.

Gribouillis 1,391 Programming Explorer Team Colleague

The problem is that there is a file calendar.py on the python path which shadows the builtin module calendar. The traceback says

"C:/Users/palmer_a/Documents/App\calendar.py"

but it should be

"C:\Python34\lib\calendar.py"

The solution is to rename the fileApp/calendar.py or to move it out of the python path or to remove the App folder from the python path.

Edit: if there is a file App/calendar.pyc , it must be removed.

Gribouillis 1,391 Programming Explorer Team Colleague
Gribouillis 1,391 Programming Explorer Team Colleague

Well, you can use the index of the python documentation https://docs.python.org/3/genindex-all.html

It could be your beginner's project: write a command line tool which tells you from which module you can import symbols.

Gribouillis 1,391 Programming Explorer Team Colleague

To empty the list, use

numbers[:] = []
Gribouillis 1,391 Programming Explorer Team Colleague

You are trying to evaluate an arithmetic expression. There are several levels of understanding of your question.

1) If you only want a working solution, you can use python's own expression evaluator:

result = eval(' '.join(str(x) for x in mylist))

this is a little bit dangerous if somebody else can send a list to your program: it could be used to evaluate arbitrary code on your computer.

2) If you are writing your own expression mini-language and your intention is to write expressions which the python interpreter does not understand, then you need a parser which is exactly this: a machine to evaluate expressions obeying a certain grammar. I recommend using wisent in this case. It is a very simple and efficient parser. But there are many similar libraries in python.

3) You may also develop your own method for parsing expressions. You can probably design a method for simple expressions such as the one in your question. Try to use list operations and tests to determine what to do. However, if you want to extend this to more complex expressions, you will have to learn a bit of the theory of parsing languages, which is a well known and well understood domain. Don't reinvent the wheel!