[Tutor] Challenge

2009-09-22 Thread Ali Sina
Hello tutor

I downloaded a guide about learning Python by Michael Dawson which has 
challenges at the end of each chapter. I'm a novice so I encountered a problem 
with this challenge:

"Write a program that flips a coin 100 times and then tells 
you the number of heads and tails."
I wrote this code but I know its wrong. Although it works properly:

flips=0
h='heads'
t='tails'
while True:
    flips+=1
    if flips>100:
    break
    if True:
    print(flips,'=',h or t)

But it prints every number with the string 'heads'. I'm really blank at this. 
It may have something to do with the 'random' module.

Regards




  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how to print a message backwards

2009-09-23 Thread Ali Sina
#Message backward printer
message=input('Enter your message: ')

for i in range(len(message),0,-1):
    print(message)


This is the code which I have written. All it does is count the number of 
letters starting from backwards. The proper code should so something like this:

Enter your message: Hi. My name is Ali Sina

Your message in backwards: aniS ilA si eman yM .iH



  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] TypeError: Need Help

2009-11-19 Thread Ali Sina
>>I have Python 3.0 and I'm trying to learn from a pdf document. I followed its 
>>instructions >>but I've encountered a problem in its Pickling chapter. This 
>>is the code I've written:

import pickle, shelve

print('Pickling list.')
variety=['sweet','hot','dill']
shape=['whole','spear','chip']
brand=['Claussen','Heinz','Vlassic']

pickle_file=open('pickles1.dat','w')
pickle.dump(variety, pickle_file)
pickle.dump(shape, pickle_file)
pickle.dump(brand, pickle_file)
pickle_file.close()

print('\nUnpickling list.')
pickle_file=open('pickles1.dat','r')
variety=pickle.load(pickle_file)
shape=pickle.load(pickle_file)
brand=pickle.load(pickle_file)
print(variety,'\n',shape,'\n',brand)
pickle_file.close()

>>But it gives this error:

Traceback (most recent call last):
  File "E:/Python/pickle it.py", line 11, in 
    pickle.dump(variety, pickle_file)
  File "C:\Python31\lib\pickle.py", line 1354, in dump
    Pickler(file, protocol, fix_imports=fix_imports).dump(obj)
TypeError: write() argument 1 must be str, not bytes

>>I read Python Docs but it didn't help me either. I hoping anyone of you could 
>>guide me or >>send the revised code itself. Thank you.

>>Regards



  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor