kind of a basic question but i cant seem to figure it out. well i have a list and i split it up using the split function but now im confusing how i can use one string and divide it to another. i tried turning it into a int or float but it didnt work. is it because its in a list? help please thanks advanced

for line in nub:
if "Total Current" in line:
word=line.split()
good=word[3]
print "09-10",good/3

pretty much im trying to get great to divide by 3 but it wont

Please provide an example of your input sentence and what you want the output to be.

input is
budget = \
"""
09-10 Expenditures
General Campus Instruction 1,831,358
Total Current Operations 4,554,328
09-10 Income
State Appropriations General Fund 2,613,200
Federal Grant and Contract Overhead 259,377
Education Fee 1,538,059
Registration Fee 193,352
Nonresident Tuition 264,851
Tuition and Fees Total 1,996,262

08-09 Expenditures
General Campus Instruction 1,690,213
Total Current Operations 3,834,169
08-09 Income
State Appropriations General Fund 3,217,297
Federal Grant and Contract Overhead 252,377
Education Fee 1,428,411
Registration Fee 188,329
Nonresident Tuition 257,243
Tuition and Fees Total 1,873,983

07-08 Expenditures
General Campus Instruction 1,689,346
Total Current Operations 3,851,215
07-08 Income
State Appropriations General Fund 3,273,916
Federal Grant and Contract Overhead 248,377
Education Fee 1,269,791
Registration Fee 167,474
Nonresident Tuition 250,000
Tuition and Fees Total 1,687,265

06-07 Expenditures
General Campus Instruction 1,575,180
Total Current Operations 3,637,275
06-07 Income
State Appropriations General Fund 3,076,681
Federal Grant and Contract Overhead 242,477
Education Fee 1,159,722
Registration Fee 152,986
Nonresident Tuition 244,500
Tuition and Fees Total 1,557,208

05-06 Expenditures
General Campus Instruction 1,480,065
Total Current Operations 3,399,057
05-06 Income
State Appropriations General Fund 2,844,906
Federal Grant and Contract Overhead 235,477
Education Fee 1,130,180
Registration Fee 149,106
Nonresident Tuition 245,800
Tuition and Fees Total 1,525,086

04-05 Expenditures
General Campus Instruction 1,422,335
Total Current Operations 3,265,099
04-05 Income
State Appropriations General Fund 2,720,841
Federal Grant and Contract Overhead 221,977
Education Fee 1,001,739
Registration Fee 141,055
Nonresident Tuition 250,900
Tuition and Fees Total 1,393,694

03-04 Expenditures
General Campus Instruction 1,546,003
Total Current Operations 3,441,558
03-04 Income
State Appropriations General Fund 2,897,965
Federal Grant and Contract Overhead 206,377
Education Fee 866,184
Registration Fee 142,251
Nonresident Tuition 209,400
Tuition and Fees Total 1,217,835

02-03 Expenditures
General Campus Instruction 1,597,078
Total Current Operations 3,704,238
02-03 Income
State Appropriations General Fund 3,223,982
Federal Grant and Contract Overhead 169,377
Education Fee 543,140
Registration Fee 139,078
Nonresident Tuition 173,040
Tuition and Fees Total 855,258

01-02 Expenditures
General Campus Instruction 1,473,750
Total Current Operations 3,785,952
01-02 Income
State Appropriations General Fund 3,357,837
Federal Grant and Contract Overhead 159,377
Education Fee 490,867
Registration Fee 125,298
Nonresident Tuition 149,200
Tuition and Fees Total 765,365

00-01 Expenditures
General Campus Instruction 1,333,390
Total Current Operations 3,576,194
00-01 Income
State Appropriations General Fund 3,205,563
Federal Grant and Contract Overhead 137,524
Education Fee 475,519
Registration Fee 121,315
Nonresident Tuition 134,500
Tuition and Fees Total 731,334
"""

nub = budget.split("\n")

output should look like this
http://img20.imageshack.us/i/ratiooutput.gif/

Member Avatar for masterofpuppets

i didn't quite understand what you're trying to do :) could you be more specific? and please use code tags next time :)

sorry, well heres the guidelines on it maybe it will help

Your program should offer the user a menu (with at least two choices in it) of ratios that it can display, for example, "State Appropriations as a percentage of Current Operations". Once the user chooses a ratio, the program should process the big sting, find the two numbers that it needs to compute the ratio every year, and print out the ratio of the two budget lines for each year.

i have to use for loops. basically i got as far as getting it to print out what i wanted but i cant seem to make a list divide by another list

this might get you started...
python does not understand a number containing commas. try the following to strip out the commas...

s = '123,456,789'
t = s.split(',')
# join will combine a sequence of strings using the separator within the quotes
#which in this case is nothing. => '123456789'
ans = int(''.join(t))/3

wow that help a bit so now i got this
for line in budgetLineList:
if "Total Current" in line:
word=line.split()
good=word[3]
float(''.join(good))
if "State" in line:
word1=line.split()
good1=word1[4]
float(''.join(good1))

print float(''.join(good1))/float(''.join(good))*100

now my probelm is that when it prints it only prints the last value it doesnt go through a loop and print the rest of it. can i get some input on this? sorry im really a begginner in python and i just learned for loops

wow that help a bit so now i got this

for line in budgetLineList:
    if "Total Current" in line:
        word=line.split()      
        good=word[3]
        float(''.join(good))
    if "State" in line:
        word1=line.split()
        good1=word1[4]
        float(''.join(good1))

print float(''.join(good1))/float(''.join(good))*100

now my probelm is that when it prints it only prints the last value it doesnt go through a loop and print the rest of it. can i get some input on this? sorry im really a begginner in python and i just learned for loops

Please use the code tags... it makes things soooo much easier to read! (http://www.daniweb.com/forums/announcement114-3.html)

Does this help you?

>>> data = \
       '''
Year: 1990
City Population 25
Total Guys 10
Total Gals 15
Total Sheep 100

Year: 1998
City Population 100
Total Guys 40
Total Gals 60
Total Sheep 1000
'''
>>> 
>>> data_list = data.split('\n')
>>> def example():
	# Loop through lines in the data_list
	for line in data_list:

		# Skip the blank line ?
		if line == '':
			continue

		# Iterator for line seperated by space
		# (without trailing spaces to prevent empty entries)
		words = line.strip().split(' ')

		# Line begins with 'Total Guys' ?
		if line.startswith('Total Guys'):

			# Print the last word in the line
			# (indexes start at 0, so we need to subtract a 1)
			print 'Total Guys: ', words[(len(words) - 1)]

			
>>> example()
Total Guys:  10
Total Guys:  40
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.