Skip to content

Query, Discussion & Bug Report #3

Open

Description

@darkprinx

Hello Guys

If anyone wants to -

  • Share opinion
  • Ideas
  • Have query
  • Find mistake

Please feel free to write it down and discuss here.


Sharing new questions and solutions are warmly welcome. Be a proud contributor of this repository by just making a pull request of your changes.

Activity

  1. changed the title [-]Question, Discussion & Bug Report[/-] [+]Query, Discussion & Bug Report[/+] on Jan 16, 2019
  2. added
    bug
    enhancement
    help wanted
    question
    on Jan 16, 2019
  3. Amitewu commented on Apr 16, 2019

    @Amitewu

    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)

  4. darkprinx commented on Apr 17, 2019

    @darkprinx
    OwnerAuthor

    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)

    Added. Thank you :)

  5. Amitewu commented on Apr 19, 2019

    @Amitewu

    In problem 17 How do I terminate this while true condition?????

  6. darkprinx commented on Apr 19, 2019

    @darkprinx
    OwnerAuthor

    Just check whether the input is empty or not.

  7. sam1037 commented on Jul 22, 2019

    @sam1037

    In answer 14, your solution 2, what is '{0}' and '{1}'? I don't understand.

  8. darkprinx commented on Jul 22, 2019

    @darkprinx
    OwnerAuthor

    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.

    Thank you :)

  9. sam1037 commented on Jul 23, 2019

    @sam1037

    Thank you for teaching me.

  10. Amitewu commented on Jul 29, 2019

    @Amitewu

    #This could be the ans for 16
    x=input().split(",")
    ans=list(filter(lambda x : int(x)%2!=0 ,x))
    print(",".join(ans))

  11. darkprinx commented on Jul 29, 2019

    @darkprinx
    OwnerAuthor

    #This could be the ans for 16
    x=input().split(",")
    ans=list(filter(lambda x : int(x)%2!=0 ,x))
    print(",".join(ans))

    Added to question# 16

  12. R2-official commented on Sep 17, 2019

    @R2-official

    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:])

  13. 199 remaining items

  14. mirohhinkov commented on Dec 31, 2023

    @mirohhinkov
  15. imyuanhui commented on Dec 31, 2023

    @imyuanhui

    Hi Yuanhui,

    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:

    print(lst,'\n',tpl,sep='')

    That's helpful!! Thank you!!!

  16. imyuanhui commented on Dec 31, 2023

    @imyuanhui

    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: @.>

    Got it, thank you!!

  17. Fatma-Nur-Azman commented on Mar 26, 2024

    @Fatma-Nur-Azman

    My own solution suggestion for question 21:

    from math import sqrt
    x = input("Please enter 4 numbers: up, down, left, right")
    
    liste_1 = [int(i) for i in x if i.isdigit()]
    
    x_ekseni = abs(liste_1[0] - liste_1[1])
    y_ekseni = abs(liste_1[2] - liste_1[3])
    robot_movement = round(sqrt(x_ekseni ** 2 + y_ekseni ** 2))
    print(f"Up:{liste_1[0]} , down :{liste_1[1]}, left:{liste_1[0]}, right:{liste_1[0]} distance: {robot_movement} ")
    
  18. Fatma-Nur-Azman commented on Mar 26, 2024

    @Fatma-Nur-Azman

    My own solution suggestion for question 88:

    list_1 = [12,24,35,24,88,120,155,88,120,155]
    list_2 = sorted(list(set(list_1)))
    list_2
    
  19. mouhazba commented on Feb 18, 2025

    @mouhazba

    My solution suggestion for question 2:

    from math import sqrt
    C = 50
    H = 30
    x = input('Type : => ').split(',')
    rsp = list(map(lambda D: str(round(sqrt(2*C*int(D)/H))), x))
    
    print(','.join(rsp))
  20. mouhazba commented on Feb 18, 2025

    @mouhazba

    My solution suggestion for question 9:

    from pathlib import Path
    file = Path("lines.txt")
    
    with file.open('w') as fp:
        while True:
            line = input('=> : \n')
            if not line:
                break
            fp.write(f'{line.upper()}\n')
    
    print('---'*25)
    with file.open('r') as f:
        while line:= f.readline():
            print(line.strip())
    
    if file.exists():
        file.unlink('lines.txt')
  21. mouhazba commented on Mar 9, 2025

    @mouhazba

    My solution suggestion for question 18:

    def pwd_check(pwd_str):
        special_chars = {'$', '#', '@'}
        
        return all([
            any(c.islower() for c in pwd_str),
            any(c.isupper() for c in pwd_str),
            any(c.isdigit() for c in pwd_str),
            any(c in special_chars for c in pwd_str),
            6 <= len(pwd_str) <= 12 
        ])
    
    
    
    str_input = input('=> : \n').split(',')
    output = list(filter(pwd_check, str_input))
    print(','.join(output))
  22. HoshimiRox1 commented on Apr 10, 2025

    @HoshimiRox1

    The Solution of question 11 can be like this:

    import functools
    
    bis = input().split(',')
    div_vis = []
    int2 = functools.partial(int, base = 2)
    
    for bi in bis:
        if int2(bi) % 5 == 0:
            div_vis.append(str(bi))
    
    print(','.join(div_vis))
  23. FelixCAxO commented on Jul 28, 2025

    @FelixCAxO

    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()])}
    """
    )

  24. hsd-coder commented on Aug 25, 2026

    @hsd-coder
    • I guess that question. 5 can also have the given alternative solution (Correct me, If I am wrong):

    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()

  25. hsd-coder commented on Aug 28, 2026

    @hsd-coder
    • 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))
  26. hsd-coder commented on Sep 1, 2026

    @hsd-coder
    • 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))))
  27. hsd-coder commented on Sep 4, 2026

    @hsd-coder
    • Question-10 can also have this solution (Correct me, If I am wrong):
      print(' '.join(sorted(list(set(input('Enter space sep words: ').split())))))
  28. hsd-coder commented on Sep 9, 2026

    @hsd-coder
    • 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugenhancementhelp wantedquestion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions