Friday, 15 April 2011

Using for loops in python to print out a calorie burnt table -



Using for loops in python to print out a calorie burnt table -

so have problem requires me print out table of calories burnt according body weight several different times 15 minutes 90 minutes growing in interval of 15 minutes. i'm having problem printing out table utilize of loops, since still on in course of study we're not allowed utilize things haven't been learnt in class yet. here code managed come with using arrays:

canoeing=3.5068/60 hiking=6.0/60 r_blading=7.5068/60 t_k_d=10.3014/60 taichi=3.0/60 activities=[canoeing,hiking,r_blading,t_k_d,taichi] activ_name=["canoeing","hiking","rollerblading","tae kwon do","tai chi"] mass=float(input("enter body mass(kg): ")) print("activity |calories in 15m |calories in 30m |calories in 45m |calories in 60m |calories in 75m |calories in 90m |") j in range(0,5): print("{:<13s}|".format(activ_name[j]), end="") in range(15,91,15): c_burnt=i*activities[j]*mass print("{:<16.4f}|".format(c_burnt),end="") print()

the sample output this:

enter body mass(kg): 55 activity |calories in 15m |calories in 30m |calories in 45m |calories in 60m |calories in 75m |calories in 90m | canoeing |48.2185 |96.4370 |144.6555 |192.8740 |241.0925 |289.3110 | hiking |82.5000 |165.0000 |247.5000 |330.0000 |412.5000 |495.0000 | rollerblading|103.2185 |206.4370 |309.6555 |412.8740 |516.0925 |619.3110 | tae kwon |141.6442 |283.2885 |424.9327 |566.5770 |708.2212 |849.8655 | tai chi |41.2500 |82.5000 |123.7500 |165.0000 |206.2500 |247.5000 |

how output using loops? see way approach using arrays. in advance

edit: clarification supposed basic, we've learnt far info types, print statements , formatting, decision structures, , loops.

python for-loop python-3.x

No comments:

Post a Comment