i cant sum the numbers (python) [closed] - python

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
Write a shell (text-based) program, called sum_num.py, that asks the user for a semicolon (;) separated list of numbers, and calculated the total. See the example below.
a = str(raw_input("Enter semicolon separated list of integers:"))
b = a.split(";")
c = (a[0:])
print("the total is " + sum(c))
PS C:\Users\ssiva\Desktop> python sum_num.py
Enter semicolon separated list of integers: 3;10;4;23;211;3
The total is 254

This code will convert into integers and sum them
a=input()
b=a.split(';')
sum=0
for num in b:
sum+=int(num)
print(sum)

Related

input function : python [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
counttonum = 1
countnum = input("[•] Provide A Number :")
while counttonum < countnum:
print("[", counttonum, "] : Number = ", counttonum)
counttonum +=1
I was trying to make a counting tool that counts up to the provided number from the “input()” function.
For example:
providedNumberFromInput = 5
output = 1
2
3
4
5
And it’ll stop if the provided number is reached. Please help me.
You are very close to solution. Problem is that input() returns value as string so you will need to convert it. And also if you want to include entered number use <= instead of <
while counttonum <= int(countnum):

I am a python student, and I have a problem [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
def thing():
_list = [1,1,5,6,8,3,4,6,10,23,5,12,67,3,25,2,6,5,4,3,2,1]
_list1 = [str(i) for i<=5 in lista]
return " ".join(_list1)
print(thing()))
I am new to this type of list managment, I am trying to put in _list1 only integers that are less then 5
so like the name of your function, it's created to calculate the sum of integers.
So basically, if your n=0 then your program will return 0 as result.
If not (else), it gonna give you a result of the calculation in return.
And here you want to print the interger sum of 451 which will give you the result of n % 10 + integer_sum(int(n / 10))

Getting Empty list in output [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
The prog is to accept 4 digit binary number separated by ','.
Then I have to print those number which is divisible by 3.
Here is my code
binary_numbers = input("Enter Binary Numbers:").split(",")
newlist = [no for no in binary_numbers if int(no)%3 == 0]
print(newlist)
when I am printing newlist I am getting empty. I dont know where is the problem.
If you want to input binary numbers, you should set the base of the int cast to 2.
[no for no in binary_numbers if int(no, 2) % 3 == 0]
binary_numbers = input("Enter Binary Numbers:").split()

How to accept n number of inputs based on an integer? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'm currently working on a problem where I have to input one number say n and based on that I need to receive n lines with one number in each. How do I split the input number into several input lines?
You loop:
nr = int(input("How many? Use a number, else crash"))
inputvalues = []
for _ in range(nr):
inputvalues.append(int(input("Input another number")))
and store the other inputs into a list.
print(inputvalues) # [1,2,3,4,5] after first input of 5 and input of 1,2,3,4,5
Further readings:
lists
int()
range()
for loops

How to program to only input words and not integers on Python [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
In my program, I wish to make the input to be words and not integers, and the inputted words are put into an array. The following variables are already declared.When I run my test data, numbers are accepted into the array.
i=o
for i in range (carers):
nm=input("Enter name")
carernm.append[nm]
You could use isdigit to check if your string contains digits
Example 1
print( all( not c.isdigit() for c in "String doesn't contain any numbers." ) )
True
Example 2
print( all( not c.isdigit() for c in "String 2 doesn't contain any numbers." ) )
False

Categories