Prev Previous Post   Next Post Next
  #1  
Old 16th September 2008, 05:23
CMYK CMYK is offline
Junior Member
 
Join Date: Sep 2008
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default changing type in python

I think I might be going about this a strange way in Python, but here's what I've been doing.
Code:
#!/usr/bin/env python

entered = raw_input("Enter numbers, separate numbers by spaces ")
numbers = entered.split(" ")
This achieves what I want but trying to pass this through a for statement and do arithmetic seems to not work
Code:
...
temp = 0
for elem in numbers:
    temp = temp + elem
So I get this error: TypeError: unsupported operand type(s) for +: 'int' and 'str'

So I guess I'm asking can you make python think that elem in the for statement is an int and definitely not a string.
Reply With Quote
Sponsored Links
 

Bookmarks

Tags
python, settype

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
chgrp error new user DKA General 15 28th July 2008 17:45
named.conf.master ISPconfig duplication hypertec_hope Installation/Configuration 0 18th July 2008 18:23
2.4.17 system needed modul8r Installation/Configuration 16 31st May 2007 14:15
Cannot create client, reseller and hosting plan crapufish Installation/Configuration 22 15th March 2007 10:27
view webalizer stats kuyaedz General 22 12th March 2006 14:45


All times are GMT +2. The time now is 09:43.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.