# To calculate the sum of numbers in a list by Python

My data

``````466.67
465.56
464.44
463.33
462.22
461.11
460.00
458.89
...
``````

I run in Python

``````sum(/tmp/1,0)
``````

I get an error.

How can you calculate the sum of the values by Python?

Asked by: Fenton381 | Posted: 06-12-2021

``````f=open('/tmp/1')
print sum(map(float,f))
``````

Answered by: Byron631 | Posted: 07-01-2022

``````sum(float(i) for i in open('/tmp/1.0'))
``````

Answered by: Roman306 | Posted: 07-01-2022

# Similar questions

python - How to calculate numbers from loop?

I'm new in python and i'm trying to calculate numbers from loop. Let this question make easy for you to understand. I've this program in python: print("Please enter your case:") myCase = input("\nEnter: ") for numCase in range(0, int(myCase)): print("\nPlease enter your number: ") myNum = input("\nEnter: ") for i in myNum: divideNum = int(myNum) % int(i) print(divideNu...

python - How to calculate pow() with modulo for real numbers?

Closed. This question needs details or clarity. It ...

python - How to calculate how many days of each season have answer equal to different numbers in pandas data frame?

I have the following data in a pandas df: Season | Answer ------ | ------ 0 4 | 0 1 4 | 0 2 2 | 0 3 1 | 1 4 4 | 1 5 2 | 1 6 3 | 0 7 1 | 0.5 8 4 | 1 9 4 | 0 I want to count how many days of each season have Answer=1, how many with answer=0.5, and how many with answer=0 to get next result: Season | Ans...

python - Calculate PI using Random Numbers

Having trouble with the following question: In geometry the ratio of the circumference of a circle to its diameter is known as π. The value of π can be estimated from an infinite series of the form: π / 4 = 1 - (1/3) + (1/5) - (1/7) + (1/9) - (1/11) + ... There is another novel approach to calculate π. Imagine that you have a dart board that is 2 units square. It inscribes a circle of unit...

python - How to calculate numbers in a list

python - Trying to calculate the sum of numbers using while loop

I'm trying to calculate the sum of multiple numbers using a while loop. When a negative number is entered the sum of the numbers should be printed. When I run the code all it does is print the last positive number entered. Here is the current non-working code: sum = 0 number = 1 while number &gt; 0: number = int(input('Enter a positive number: ')) if number &gt; 0: tot = sum + number print("...

python - Calculate how many numbers were summed from 1 to n

I have a math question. Having a sum of number from 1 to n. For example it may be: sum([i for i in range(46)]) So the sum of it equals 1035. Now my question is, knowing just sum - 1035 and that we start from 1. I want to calculate n. How can I do that

python - I need to calculate mean, median and std but asking the user numbers until user puts 0

import numpy as np count = 0 number = 1 while number != 0: number = int(input(&quot;Enter values&quot;)) print(np.mean(number)) print(np.median(number)) print(np.std(number)) if count == 0: print(&quot;let's see some values&quot;) print(np.mean(number)) print(np.median(number)) print(np.std(number)) So far this is what I got but I keep getting an error when tr...

How can i calculate sum of all numbers in text with python?

input essum magis 45 kohlrabi azuki bean garlic. Dandelion cucumber -1 earthnut pea peanut water 10.5 spinach fennel kombu maize bamboo shoot green output 54.5 explanation 45 + 10.5 -1 = 54.5 I'm not allowed to import packages yet! im really lost i have been working on this for the 4 hours n = input('Enter an Alpha-Numeric String: ') n_sum = 0 temp_num = '' for i in n: if i.isalpha()...

python - How to calculate the median of a list of numbers from a CSV file?

I was working on doing a short function on finding a median from a list. Here is a portion of the csv file: Index,Height(Inches),Weight(Pounds) 1,65.78331,112.9925 2,71.51521,136.4873 3,69.39874,153.0269 4,68.2166,142.3354 5,67.78781,144.2971 6,68.69784,123.3024 7,69.80204,141.4947 8,70.01472,136.4623 9,67.90265,112.3723 10,66.78236,120.6672 11,66.48769,127.4516 12,67.62333,114.143 13,68.30248,125.6107 1...

python - How can I calculate the range from 0 to 1 with 52 numbers in between?

I am trying to print out a list that calculates 52 numbers between 0 to 1 (so a lot of float numbers are expected in the output). However, when I tried doing this in Python, it's printing out 0: for i in range(0,1,52): print(i) Apologies, I am an absolute beginner and trying to learn!

python - Calculate the sum of all numbers from 1 to a given number using for loop (Also pls tell me where i am wrong)

number = int(input(&quot;Enter the number: &quot;)) for i in range(1, number+1): print(sum(i)) #this where i left and pls tell where i am wrong

python - How can I calculate numbers in a list?

For example, we have these lists: l1 = [1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 4] l2 = [11, 11, 2] l3 = [5, 6] l4 = [1, 2, 3, 3, 3] Here, l2 and l3 have 2 numbers (11 and 2 for l2, and 5 and 6 for l3) l1 has 4 numbers (1, 2...

python - calculate the digits of the Nth number using the given numbers

Closed. This question needs to be more focused. It ...

python - How to calculate sum of numbers in a list?

I am trying to write a program in which the user enters the age of 8 guests. Each guest's age is priced differently. How can I add each cost together to come up with the total cost for each guest? This is what I have written. def main(): guest1= int(input(&quot;Enter the age of guest 1(in years): &quot;)) guest2 = int(input(&quot;Enter the age of guest 2(in years): &quot;)) guest3 = int(input(&qu...

python - How to calculate numbers from loop?

I'm new in python and i'm trying to calculate numbers from loop. Let this question make easy for you to understand. I've this program in python: print("Please enter your case:") myCase = input("\nEnter: ") for numCase in range(0, int(myCase)): print("\nPlease enter your number: ") myNum = input("\nEnter: ") for i in myNum: divideNum = int(myNum) % int(i) print(divideNu...

python - How to calculate pow() with modulo for real numbers?

Closed. This question needs details or clarity. It ...

How do I calculate total numbers of days, hours, and minutes using python pandas?

This is my dataframe. I want to find total time taken from particular product. product,query,time1,time2 A,a1,25-06-15 08:42:43.830000000 PM,25-06-15 08:42:43.830000000 PM A,a2,03-07-15 11:57:10.557000000 AM,03-07-15 11:57:10.557000000 AM A,a3,02-07-15 02:32:33.090000000 PM,02-07-15 02:32:33.090000000 PM A,a4,04-07-15 11:51:59.090000000 AM,04-07-15 11:51:59.090000000 AM A,a5,27-06-15 07:12:30.250000000 PM,2...

python - How to calculate how many days of each season have answer equal to different numbers in pandas data frame?

I have the following data in a pandas df: Season | Answer ------ | ------ 0 4 | 0 1 4 | 0 2 2 | 0 3 1 | 1 4 4 | 1 5 2 | 1 6 3 | 0 7 1 | 0.5 8 4 | 1 9 4 | 0 I want to count how many days of each season have Answer=1, how many with answer=0.5, and how many with answer=0 to get next result: Season | Ans...

python - Calculate PI using Random Numbers

Having trouble with the following question: In geometry the ratio of the circumference of a circle to its diameter is known as π. The value of π can be estimated from an infinite series of the form: π / 4 = 1 - (1/3) + (1/5) - (1/7) + (1/9) - (1/11) + ... There is another novel approach to calculate π. Imagine that you have a dart board that is 2 units square. It inscribes a circle of unit...

python - How to calculate numbers in a list

python - Trying to calculate the sum of numbers using while loop

I'm trying to calculate the sum of multiple numbers using a while loop. When a negative number is entered the sum of the numbers should be printed. When I run the code all it does is print the last positive number entered. Here is the current non-working code: sum = 0 number = 1 while number &gt; 0: number = int(input('Enter a positive number: ')) if number &gt; 0: tot = sum + number print("...

python - Calculate sum of string of numbers from a file, while the numbers are in random rows

I have a file with numbers that are in rows, with random amount of numbers in each row. And I need to calculate the sum. My input is like so: 63,59,39,5,99,35,56 58,19,35,34,88,55,38,47,90 38,46,33,62,9,58,54,34,37 78,72,25,56,17 The code I have so far is: def sumIs(file): line = file.readlines() lines = [line.split(",") for line in file] removed = [line...

python - Calculate how many numbers were summed from 1 to n

I have a math question. Having a sum of number from 1 to n. For example it may be: sum([i for i in range(46)]) So the sum of it equals 1035. Now my question is, knowing just sum - 1035 and that we start from 1. I want to calculate n. How can I do that

python - What's the best way to calculate a 3D (or n-D) centroid?

As part of a project at work I have to calculate the centroid of a set of points in 3D space. Right now I'm doing it in a way that seems simple but naive -- by taking the average of each set of points, as in: centroid = average(x), average(y), average(z) where x, y and z are arrays of floating-point numbers. I seem to recall that there is a way to get...

How Python calculate number?

python - Calculate score in a pyramid score system

I am trying to calculate gamescores for a bunch over users and I haven't really got it yet. It is a pyramid game where you can invite people, and the people you invite is placed beneth you in the relations tree. So if i invite X and X invites Y i get kickback from both of them. Let's say 10%^steps... So from X i get 10% of his score and 1% from Y, and X get 10% from Y. So to calculate this i was thi...

How to calculate a mod b in Python?

Is there a modulo function in the Python math library? Isn't 15 % 4, 3? But 15 mod 4 is 1, right?

python - How to calculate a date back from another date with a given number of work days

I need to calculate date (year, month, day) which is (for example) 18 working days back from another date. It would be enough to eliminate just weekends. Example: I've got a date 2009-08-21 and a number of 18 workdays as a parameter, and correct answer should be 2009-07-27. thanks for any help

python - How to calculate the scrape URL for a torrent

I've read the Bit-torrent specification and done a number of searches, trying to find out how I can get the seeds/peers/downloaded data from a torrent tracker (using Python). I can calculate the info hash from a Torrent no problem, which matches up with the info hash given by various working torrent applications. However, when I try to get the information from the tracker I either timeout (the tracker is working) o...

datetime - How to use Python to calculate time

I want to write python script that acts as a time calculator. For example: Suppose the time is now 13:05:00 I want to add 1 hour, 23 minutes, and 10 seconds to it. and I want to print the answer out. How do I do this in Python? What if date is also involved?

c# - Calculate percent at runtime

I have this problem where I have to "audit" a percent of my transtactions. If percent is 100 I have to audit them all, if is 0 I have to skip them all and if 50% I have to review the half etc. The problem ( or the opportunity ) is that I have to perform the check at runtime. What I tried was: audit = 100/percent So if percent is 50 audit = 100 /...

python - Calculate time between time-1 to time-2?

enter time-1 // eg 01:12 enter time-2 // eg 18:59 calculate: time-1 to time-2 / 12 // i.e time between 01:12 to 18:59 divided by 12 How can it be done in Python. I'm a beginner so I really have no clue where to start. Edited to add: I don't want a timer. Both time-1 and time-2 are entered by the user manually. Thanks in advance for your help.

python - How to calculate positions of holes in a game board?

I'm making a game with Python->PyGame->Albow and ran into a problem with board generation. However I'll try to explain the problem in a language agnostic way. I believe it's not related to python. I've split the game board generation into several parts. Part one generates the board holes. Holes are contained in a list/array. Each hole object has a mapping of angles relating to other...