You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Solution Can be of question 14:
string=input("Enter the sentense")
upper=0
lower=0
for x in string:
if x.isupper()==True:
upper+=1
if x.islower()==True:
lower+=1
Solution Can be of question 14:
string=input("Enter the sentense")
upper=0
lower=0
for x in string:
if x.isupper()==True:
upper+=1
if x.islower()==True:
lower+=1
In python, while printing a dynamic value inside a string, there are several ways to format the output string. For example, let's say you have two variables a = 10 and b = 20 and you want to output something like this,
The sum of 10 and 20 is 30
You can do this by writing it in this way,
print("The sum of {0} and {1} is {2}".format(a, b, a + b))
Here 0, 1, 2 inside '{ }' represents the order of a, b and a+b respectively.
However, If the code is written in this way,
print("The sum of {1} and {0} is {2}".format(a, b, a + b))
then the output will be like,
The sum of 20 and 10 is 30
But printing in this way is not very much necessary. It can be also written in this way,
print("The sum of {} and {} is {}".format(a, b, a + b))
which will give the same output as wanted. I was new to python at that timeline so that I learned and used in {0}, {1} style which is actually not mandatory at all.
On Sun, 31 Dec 2023, 06:54 YuanhuiAtGit, ***@***.***> wrote:
*Indentation Issue with print(lst, '\n', tpl) in Python*
Description:
I am a beginner of python. And I faced an unexpected indentation problem
when using the print function in Python. The issue is specifically observed
when using print(lst, '\n', tpl) compared to print(f"{lst}\n{tpl}"). The
latter works as expected, but the former introduces an indentation on the
second line.
image.png (view on web)
<https://github.com/darkprinx/break-the-ice-with-python/assets/154571770/963eec89-4b8a-4a0f-90fb-dd8b2482feaf>
here is my code:
def generate_list_and_tuple():
seq = input()
seq = seq.split(",")
lst = [elem.strip() for elem in seq]
tpl = tuple(lst)
print(f"{lst}\n{tpl}") #this one works correctly
print(lst,'\n',tpl) #this one causes an indentation on the second line
I would like to understand why this indentation occurs and how to prevent
it while using the print function with multiple arguments.
Any insights into the root cause and a resolution would be greatly
appreciated.
—
Reply to this email directly, view it on GitHub
<#3 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQC3OGWFMW66P6RZC4QQUATYMDVXJAVCNFSM4GQP6TLKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBXGI3DOMBXGYYA>
.
You are receiving this because you commented.Message ID:
***@***.***>
Let's take a look at Python's source code for the built-in print function. For print, as it is as built-in function, you can find this information executing help(print).
The source code contains the following:
print as builtin_print
*args: object
sep: object(c_default="Py_None") = ' '
string inserted between values, default a space.
end: object(c_default="Py_None") = '\n'
string appended after the last value, default a newline.
file: object = None
a file-like object (stream); defaults to the current sys.stdout.
flush: bool = False
whether to forcibly flush the stream.
We find out that by default a space separates values in a string. Rewriting your code as follows removes the indent because the separator is assigned an empty:
Hi, print function in Python adds a space between passed values. That's why you have an extra space after the new line. …
On Sun, 31 Dec 2023, 06:54 YuanhuiAtGit, @.> wrote: Indentation Issue with print(lst, '\n', tpl) in Python Description: I am a beginner of python. And I faced an unexpected indentation problem when using the print function in Python. The issue is specifically observed when using print(lst, '\n', tpl) compared to print(f"{lst}\n{tpl}"). The latter works as expected, but the former introduces an indentation on the second line. image.png (view on web) https://github.com/darkprinx/break-the-ice-with-python/assets/154571770/963eec89-4b8a-4a0f-90fb-dd8b2482feaf here is my code: def generate_list_and_tuple(): seq = input() seq = seq.split(",") lst = [elem.strip() for elem in seq] tpl = tuple(lst) print(f"{lst}\n{tpl}") #this one works correctly print(lst,'\n',tpl) #this one causes an indentation on the second line I would like to understand why this indentation occurs and how to prevent it while using the print function with multiple arguments. Any insights into the root cause and a resolution would be greatly appreciated. — Reply to this email directly, view it on GitHub <#3 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQC3OGWFMW66P6RZC4QQUATYMDVXJAVCNFSM4GQP6TLKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBXGI3DOMBXGYYA . You are receiving this because you commented.Message ID: @.>
Day-6, Question-18 can also have this solution (Correct me, If I am wrong):
p,l = input().split(','),[]
for i in p:
a,d,A,s = 0,0,0,0
for j in i:
if 'a'<= j <='z':
a += 1
if '0'<= j <='9':
d += 1
if 'A'<= j <='Z':
A += 1
if j == '#' or j == '$' or j == '@':
s += 1
if a > 0 and d > 0 and A > 0 and s >0 and 5 < len(i) <13:
l.append(i)
print(','.join(l))
Day-11, Question-39 can also have this solution (Correct me, If I am wrong):
print([i for i in (1,2,3,4,5,6,7,8,9,10) if i % 2 == 0])
or
print(tuple(filter(lambda i : i %2 == 0, (1,2,3,4,5,6,7,8,9,10))))
Question-96 can also have this solution without BUILT-IN FUNCTIONS as follows: (Correct me, If I am wrong)
s,w,k = input('Enter S '),int(input("Enter the W ")),0
lst = [''] * len(s)
for i in range(len(s)):
j = 0
while j < w:
if k < len(s):
lst[i] = lst[i] + s[k]
j += 1
k += 1
lst2 = [i for i in lst if i != '']
for i in lst2:
print(i)
Activity
[-]Question, Discussion & Bug Report[/-][+]Query, Discussion & Bug Report[/+]Amitewu commentedon Apr 16, 2019
Solution Can be of question 14:
string=input("Enter the sentense")
upper=0
lower=0
for x in string:
if x.isupper()==True:
upper+=1
if x.islower()==True:
lower+=1
print("UPPER CASE: ",upper)
print("LOWER CASE: ",lower)
darkprinx commentedon Apr 17, 2019
Added. Thank you :)
Amitewu commentedon Apr 19, 2019
In problem 17 How do I terminate this while true condition?????
darkprinx commentedon Apr 19, 2019
Just check whether the input is empty or not.
sam1037 commentedon Jul 22, 2019
In answer 14, your solution 2, what is '{0}' and '{1}'? I don't understand.
darkprinx commentedon Jul 22, 2019
In python, while printing a dynamic value inside a string, there are several ways to format the output string. For example, let's say you have two variables a = 10 and b = 20 and you want to output something like this,
The sum of 10 and 20 is 30You can do this by writing it in this way,
print("The sum of {0} and {1} is {2}".format(a, b, a + b))Here 0, 1, 2 inside '{ }' represents the order of a, b and a+b respectively.
However, If the code is written in this way,
print("The sum of {1} and {0} is {2}".format(a, b, a + b))then the output will be like,
The sum of 20 and 10 is 30But printing in this way is not very much necessary. It can be also written in this way,
print("The sum of {} and {} is {}".format(a, b, a + b))which will give the same output as wanted. I was new to python at that timeline so that I learned and used in {0}, {1} style which is actually not mandatory at all.
Thank you :)
sam1037 commentedon Jul 23, 2019
Thank you for teaching me.
Amitewu commentedon Jul 29, 2019
#This could be the ans for 16
x=input().split(",")
ans=list(filter(lambda x : int(x)%2!=0 ,x))
print(",".join(ans))
darkprinx commentedon Jul 29, 2019
Added to question# 16
R2-official commentedon Sep 17, 2019
Question 38 ans proposition:
tup = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
lt = int(len(tup)/2)
print(tup[:lt], tup[lt:])
199 remaining items
mirohhinkov commentedon Dec 31, 2023
imyuanhui commentedon Dec 31, 2023
That's helpful!! Thank you!!!
imyuanhui commentedon Dec 31, 2023
Got it, thank you!!
Fatma-Nur-Azman commentedon Mar 26, 2024
My own solution suggestion for question 21:
Fatma-Nur-Azman commentedon Mar 26, 2024
My own solution suggestion for question 88:
mouhazba commentedon Feb 18, 2025
My solution suggestion for question 2:
mouhazba commentedon Feb 18, 2025
My solution suggestion for question 9:
mouhazba commentedon Mar 9, 2025
My solution suggestion for question 18:
HoshimiRox1 commentedon Apr 10, 2025
The Solution of question 11 can be like this:
FelixCAxO commentedon Jul 28, 2025
Hi,
my solution to problem 13:
input = input()
print(
f"""
Letters {len([c for c in input if c.isalpha()])}
Digits {len([c for c in input if c.isdigit()])}
"""
)
hsd-coder commentedon Aug 25, 2026
class String:
def getString(self):
string = input('Enter anything: ')
return string
def printString(self):
print(self.getString().upper()) #s1.getstring().upper() == string.upper()
s1 = String()
s1.printString()
hsd-coder commentedon Aug 28, 2026
p,l = input().split(','),[]
for i in p:
a,d,A,s = 0,0,0,0
for j in i:
if 'a'<= j <='z':
a += 1
if '0'<= j <='9':
d += 1
if 'A'<= j <='Z':
A += 1
if j == '#' or j == '$' or j == '@':
s += 1
if a > 0 and d > 0 and A > 0 and s >0 and 5 < len(i) <13:
l.append(i)
print(','.join(l))
hsd-coder commentedon Sep 1, 2026
print([i for i in (1,2,3,4,5,6,7,8,9,10) if i % 2 == 0])
or
print(tuple(filter(lambda i : i %2 == 0, (1,2,3,4,5,6,7,8,9,10))))
hsd-coder commentedon Sep 4, 2026
print(' '.join(sorted(list(set(input('Enter space sep words: ').split())))))
hsd-coder commentedon Sep 9, 2026
s,w,k = input('Enter S '),int(input("Enter the W ")),0
lst = [''] * len(s)
for i in range(len(s)):
j = 0
while j < w:
if k < len(s):
lst[i] = lst[i] + s[k]
j += 1
k += 1
lst2 = [i for i in lst if i != '']
for i in lst2:
print(i)