Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using For in Python

Status
Not open for further replies.

rubicina

Programmer
Apr 10, 2007
1
0
0
PE
I want to get a suma, but as a result I have tmin1tmin2. Please how shoul I solve this?

for n in range (1,2):
tmin1=10
tmin2=14
tasa = "tmin"+str(n)+ "tmin"+str(n+1)

print tasa
 

I think he wanted to print '24' rather than 'tmin1tmin2'. Here's one way to do it.


Code:
for n in range (1,2):
  tmin1=10
  tmin2=14

  exec 'tasa = %s + %s' %('tmin' + str(n), 'tmin' + str(n+1))

  print tasa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top