This question already has answers here:
How can I print multiple things on the same line, one at a time?
(18 answers)
Print in one line dynamically [duplicate]
(22 answers)
Closed 6 years ago.
I'm searching for printing this :
random_numbers = [1, 5, 25, 4, 60]
print("Numbers are : ")
for elem in random_numbers :
print(elem, end=' ')
and the result have to be like this :
Numbers are : 1 5 25 4 60
So on the same line, with space and no quote. I searched for this on several forums and try to put in a function and call it right after printing "Numbers are : " but nothing worked, please help!
Related
This question already has answers here:
multiplication of two arguments in python [duplicate]
(6 answers)
Getting issue while trying to multiply string and integer [duplicate]
(2 answers)
Closed 3 months ago.
I want to output 5 * 2 = 10 but python output is 55!
How do I resolve this problem?
a = 0
b = 2
a = input("a? :") #(get 5 as input)
c = a * b
print (c)
This is my code.
when I input a number it repeat same number I entered two times insterd of showing multipiy it. What do I have to do to solve this?
a is a string,
so it will be
'5'*2='55'
if you want 10, you need to cast a to int.
a=int(input())
here is the link to document
https://docs.python.org/3/library/functions.html#input
This question already has answers here:
Why is "None" printed after my function's output?
(7 answers)
Why is this printing 'None' in the output? [duplicate]
(2 answers)
Closed 1 year ago.
This is my code, when I run it gives me the right answer but also it gives me 'None':
My Code:
def art() :
a = input('enter a values')
b = eval(a)
print(b)
print(art())
Output:
enter a values3 + 4
7
None
Does anyone know why is that and how to remove it? Thank you.
This question already has answers here:
How can I print multiple things on the same line, one at a time?
(18 answers)
Closed 3 years ago.
I want to know how to print output in a single line
I want to print it like: 1234
instead of
1
2
3
4
Code:
# n = (get in from user)
i=1
while (i<=n):
print (i,)
i +=1
This may help :
For Python 3:
print(i,end='')
For Python 2:
print(i),
This question already has answers here:
Why are str.count('') and len(str) giving different output?
(3 answers)
Closed 4 years ago.
I was going through something when i came across this...
a = 'hello'
print(a.count('l'))
print(a.count(''))
Output is :
2
6
Can anyone explain why the second output is 6 ?
count here returns the number of occurences of your substring, here a '' string.
There are indeed six '' in hello, between each char:
print(''.count('')) # >> 1
# You could symbolize it like that:
print('a'.count('')) # >> 2
# is equivalent to:
print('|a|'.count('|')) # >> 2
This question already has answers here:
String of numbers to a list of integers?
(4 answers)
Closed 5 years ago.
The following block of code was tested on python 2.
A="1 2 10"
A=raw_input.split()
print A
This prints a list with 4 numbers(splitting the 10 into 1 and 0),
Why does this happen?
Just use normal split
B = A.split()