```
# sum up the ascii values of the characters in a word
word = "arguments"
ascii_sum = 0
for c in word:
ascii_value = ord(c)
ascii_sum += ascii_value
print(ascii_sum) # --> 982
```

Find three words that have an ascii sum of 1000.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

```
# sum up the ascii values of the characters in a word
word = "arguments"
ascii_sum = 0
for c in word:
ascii_value = ord(c)
ascii_sum += ascii_value
print(ascii_sum) # --> 982
```

Find three words that have an ascii sum of 1000.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

This could be an interesting historical project. From

http://en.wikipedia.org/wiki/State_of_the_Union

pick a number of "State of the Union" speeches. Then write a Python program that counts the 50 most common words sorted by frequency in each speech.

Hint:

take a look at module collections.Counter

you may need to preprocess the text, remove punctuation marks and convert to all lower case words

Edited by vegaseat

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Edited by vegaseat

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Create a calculator using a dictionary ...

```
''' dict_calculator101.py
create a simple reverse polish calculator using a dictionary
'''
import math
def do_op(op, a=1, b=1):
"""use of a dictionary similar to C's switch/case"""
return {
'+': lambda: a + b,
'-': lambda: a - b,
'*': lambda: a * b,
'/': lambda: a / b,
'//': lambda: a // b, # floor
'**': lambda: a ** b, # power
'sin': lambda: math.sin(a),
'cos': lambda: math.cos(a),
'asin': lambda: math.asin(a),
'acos': lambda: math.acos(a)
}[op]()
# testing ...
# 355/113.0 pi approx.
print(do_op('/', 355, 113.0)) # 3.1415929203539825
# sqroot(25)
print(do_op('**', 25, 0.5)) # 5.0
# asin(sin(0.5))
print(do_op('asin', do_op('sin', 0.5))) # 0.5
```

Your mission is to expand the dictionary.

Edited by vegaseat

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Use Python to show that factorial(0.5) = sqrt(pi)/2

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Explore Collatz numbers (the 3n+1 problem, L. Collatz in 1937)

http://mathworld.wolfram.com/CollatzProblem.html

Take any number, if even divide it by 2, if odd multiply it by 3 and add one,

should converge to 2 (ultimately to 1).

For instance starting with 7 ...

7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]]

into a single list like

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

```
# a Python code riddle, can you figure it out?
print(chr(98) + ''.join (['natural fruit'[:2][int(i==0) : 2+int(i==2)] for i in range(3)]))
```

Can you come up with some of your own code riddles?

Edited by vegaseat

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

bdodobird 0 Newbie Poster

sneekula 969 Nearly a Posting Maven

Write a Python program that checks a given directory for any file changes over a given period.

sneekula 969 Nearly a Posting Maven

If you go to:

http://en.wikipedia.org/wiki/List_of_countries_by_inflation_rate

you can extract the 10 countries with the highest inflatuion rate.

You end up with this tab delimited data string:

```
data = '''\
Uruguay 8.11 2014 November
Turkey 8.9 2014 November
Egypt 10.61 2014 June
Argentina 24.2 2014 November
Ukraine 13 2014 December
Syria 13.6 2014 February
Iran 14.6 2014 June
Belarus 32.8 2014 December
Sudan 46.8 2014 July
Venezuela 60.9 2014 May'''
```

Now write a Python program to produce this string/text:

```
Country Inflation (%)
Venezuela 60.9
Sudan 46.8
Belarus 32.8
Argentina 24.2
Iran 14.6
Syria 13.6
Ukraine 13.0
Egypt 10.61
Turkey 8.9
Uruguay 8.11
```

HiHe 174 Junior Poster

Explain the output of this code:

```
# generator expression
g = lambda: ((yield x) for x in range(5))
z = g()
for k in range(5):
print(next(z))
```

Gribouillis commented: Not for beginners! Hint: search yield expressions +0

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

The program should help answer some questions like:

What is the path of a new law from inception to final approval?

What is the procedure to start a new war?

What is the procedure to aid victims of a natural disaster?

At what level is the abuse of power or corruption most dangerous?

Who governs the banking system?

How is a supreme court judge selected and what are the basic requirements of the position?

How is the president elected?

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Write a program that scrambles each word in a sentence preserving the spaces.

For fun unscamble this sentence ...

scramble = "yaplgoo eeltrt mrfo het ondomc ocarfty"

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Sort the characters in a word. eg. combine --> bceimno

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Swap every two words in a text.

For instance

"is the zebra considered black or white"

would turn into

"the is considered zebra or black white"

Important, make it work for text with an odd number of words as shown above.

Edited by vegaseat

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Enter a phrase and scramble the word order.

For instance

"advice is easier to give than to receive"

could turn into

"to give to than advice is easier receive"

Ask your friends to come up with the right phrase from the scrambled phrase.

BustACode 15 Light Poster

Good stuff, and ideas. Thanks.

I am not a "spammer," but I do eat Spam. Does that make me a spammee?

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Create an example of a nested list comprehension.

BustACode 15 Light Poster

What has helped me a lot is researching in areas of Python that I do not currently need. I didn't need to use generators, but I pushed to learn how to create and use them, and now I do use them. Also, while learning generators, I began to learn comprehensions (still haven't mastered them).

Then of course one should always be learning how to manipulate and present strings. Much of what I learned from learning string manipulation and presentation has helped me with Regular Expressions.

Learn Regular Expressions now, as it is painful to have to learn them under pressure when you are trying to complete a project.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Simple Algebra ...

let

a = b

add a to each side

a + a = a + b

simplify left side since a + a is equal to 2a

2a = a + b

now subtract 2b from each side

2a - 2b = a + b - 2b

simplify left side since 2a - 2b is equal to 2(a - b)

2(a - b) = a + b - 2b

simplify right side since a + b - 2b is equal to a - b

2(a - b) = a - b

now divied both sides by (a - b), wowie zowie ...

2 = 1

Use Python to show that this cannot be right!

mathwizurd 0 Newbie Poster

I wrote something pretty cool that didn't require a lot of python experience:

I made a simple AI rock paper scissors program. It just looked at the most common chains of n moves, called a Markov chain, and predicted the next move like that.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

```
# a cook has a list of ingredients from a recipe
ingredients = ["flour", "lard", "almonds", "sugar", "cinnamon"]
# items in the kitchen's pantry, spice drawer and cooler
pantry = ["flour", "sugar", "almonds", "peanuts", "olive oil"]
drawer = ["cinnamon", "salt", "pepper", "garlic"]
cooler = ["milk", "butter", "beef", "chicken", "fish"]
kitchen = pantry + drawer + cooler
# check if all ingredients are in the kitchen
# if not, show the missing ingredient(s)
```

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Examine the Golden Ratio and how it relates to the Fibonacci numbers.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.