Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query, Discussion & Bug Report #3

Open
darkprinx opened this issue Jan 16, 2019 · 214 comments
Open

Query, Discussion & Bug Report #3

darkprinx opened this issue Jan 16, 2019 · 214 comments
Labels
bug Something isn't working enhancement New feature or request help wanted Extra attention is needed question Further information is requested

Comments

@darkprinx
Copy link
Owner

darkprinx commented Jan 16, 2019

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.

@darkprinx darkprinx changed the title Question, Discussion & Bug Report Query, Discussion & Bug Report Jan 16, 2019
@darkprinx darkprinx added bug Something isn't working enhancement New feature or request help wanted Extra attention is needed question Further information is requested labels Jan 16, 2019
@Amitewu
Copy link

Amitewu commented 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
Copy link
Owner Author

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

@Amitewu
Copy link

Amitewu commented Apr 19, 2019

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

@darkprinx
Copy link
Owner Author

Just check whether the input is empty or not.

@sam1037
Copy link

sam1037 commented Jul 22, 2019

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

@darkprinx
Copy link
Owner Author

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

@sam1037
Copy link

sam1037 commented Jul 23, 2019

Thank you for teaching me.

@Amitewu
Copy link

Amitewu commented 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
Copy link
Owner Author

#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

@ArturOle
Copy link

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

@darkprinx
Copy link
Owner Author

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

Added. Thank you.

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

@dwedigital
Copy link

For Q. 16 the answers are all wrong.

You say square each odd number yet your demo answer just prints odd numbers

The correct answer is:

num = input("Enter numbers: ").split(',')

print (",".join([str(int(x)**2) for x in num if int(x)%2 != 0]))

@darkprinx
Copy link
Owner Author

For Q. 16 the answers are all wrong.

You say square each odd number yet your demo answer just prints odd numbers

The correct answer is:

num = input("Enter numbers: ").split(',')

print (",".join([str(int(x)**2) for x in num if int(x)%2 != 0]))

Yes, I also noticed the mistake. It's now fixed. Thank you for the cooperation :)

@leonedott
Copy link

Hi! I don't completely understand how the solution for question 9 works.
Why is it a list what is created?
Also, when I run the solution on my computer, the result is not capitalized.

@darkprinx
Copy link
Owner Author

Hi! I don't completely understand how the solution for question 9 works.
Why is it a list what is created?
Also, when I run the solution on my computer, the result is not capitalized.

Hi Leonedott,
I did a little mistake in the given code for python3. Thus, the result wasn't showing to you as expected. The code has been fixed. Now I'm explaining how the solution works.

As the question says, a program that accepts sequence of lines that means the output will come after all the sequence of lines are taken. That's why a list is created to save the processed inputs and then show them all together as output.

The program will take input until there is an empty line. The program will take a line as input, then make it upper case and append in the list. If the program founds any empty string line, it will break and come out of the loop, and then show all the lines which are saved in the list.

If you still have any queries, please feel free to ask. Thank you :)


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

@leonedott
Copy link

Here's my solution to exercise 17

`lst = []
while True:
x = input(': ')
if len(x)==0:
break;
lst.append(x)

balance = 0
for item in lst:
if 'D' in item:
balance += int(item.strip('D '))
if 'W' in item:
balance -= int(item.strip('W '))
print(balance)`

Thanks so much for these exercises @darkprinx !!!

@darkprinx
Copy link
Owner Author

Here's my solution to exercise 17

`lst = []
while True:
x = input(': ')
if len(x)==0:
break;
lst.append(x)

balance = 0
for item in lst:
if 'D' in item:
balance += int(item.strip('D '))
if 'W' in item:
balance -= int(item.strip('W '))
print(balance)`

Thanks so much for these exercises @darkprinx !!!

Thanks for sharing your solution. There was a little mistake. I corrected it and added it.

@vibhu077
Copy link

vibhu077 commented Nov 6, 2019

Who is the main author plzz telll me sir,@darkprinx

@MarkisLandis
Copy link

Problem with Question 70.
It says random even integer from 0 to 10. 0 is even. But they left it out.

@darkprinx
Copy link
Owner Author

Who is the main author plzz telll me sir,@darkprinx

I actually mentioned where I get these problems. It's all described here in the readme.
https://github.com/darkprinx/100-plus-Python-programming-exercises-extended

I tend to mention the person as the main author coz the source I found first from his repository.

@darkprinx
Copy link
Owner Author

Problem with Question 70.
It says random even integer from 0 to 10. 0 is even. But they left it out.

It was a mistake in my code of python3. I mistakenly ignored 0 as a member of the list. I fixed it now. Thank you very much for the co-operation :-)

@vibhu077
Copy link

vibhu077 commented Dec 4, 2019 via email

@yuan1z
Copy link

yuan1z commented Dec 22, 2019

Answer for Question #30
func = lambda a,b: print(max((a,b),key=len)) if len(a)!=len(b) else print(a+'\n'+b)

@yuan1z
Copy link

yuan1z commented Dec 22, 2019

Question #34 answer
func = lambda :print([i**2 for i in range(1,21)][:5])

@darkprinx
Copy link
Owner Author

Question #34 answer
func = lambda :print([i**2 for i in range(1,21)][:5])

Both solutions are added. Thank you :)

@cen6wkf
Copy link

cen6wkf commented Feb 3, 2023

Question 97:
def rangoli(N):
for i in range(1, 2N):
j = abs(int((2
N-1)/2)+1-i)
str_hf = '-'.join(x for x in reversed('abcdefghijklmnopqrstuvwxyz'[j:N]))
str_hf = ''.join('-' for x in range(2*j)) + str_hf
str_ra = str_hf + str_hf[-2::-1]
print(str_ra)
rangoli(9)

@cen6wkf
Copy link

cen6wkf commented Feb 4, 2023

Question 102:
str_in, ct_d, ct_l = input(), 0, 0
for i in str_in: ct_d, ct_l = ct_d+i.isdigit(), ct_l+i.isalpha()
print('Digit - ' + str(ct_d) + '\n' + 'Letter - ' + str(ct_l))

@cen6wkf
Copy link

cen6wkf commented Feb 4, 2023

Question 103:
f = lambda x: x+f(x-1) if x>1 else x
print(f(int(input())))

@PeterFil
Copy link

Hi, I am a newbie, however, could not help and notice that in question 1 in the first python3 solution, there is this:
for i in range(2000,3201):
if i%7 == 0 and i%5!=0:
print(i,end=',')
print("\b") # I don't think we even need this line (it prints the same without it)
Unless there is a reason I do not know yet... I would be glad for the comments ;)

@PeterFil
Copy link

PeterFil commented Feb 26, 2023

Question 2 in while loop I am getting ValueError:
n = int(input()) #input() function takes input as string type
#int() converts it to integer type
fact = 1
i = 1
while i <= n:
fact = fact * i;
i = i + 1
print(fact)

@arutrr0
Copy link

arutrr0 commented Mar 3, 2023

Question 1:

lst = list(filter(lambda i: i % 7 == 0 and i % 5 != 0, range(2000,3201)))
single_line = ", ".join(map(str,lst))
print(single_line)

@arutrr0
Copy link

arutrr0 commented Mar 5, 2023

Question 14:

sentence = input("Enter a sentence: ")
print(f"UPPER CASE: {sum(1 for i in sentence if i.isupper())}")
print(f"UPPER CASE: {sum(1 for i in sentence if i.islower())}")

@03guptashubham
Copy link

Hello.
I am new to the python coding.
I have taken the ZTM Python course and i have came down till here. Today i tried these 3 questions out of which i cant solve even one of them.
Could anyone please tell me if i am into the right direction of my career or not. I mean is it normal for person to not solve any of these simplest question

@cen6wkf
Copy link

cen6wkf commented May 21, 2023

Hello. I am new to the python coding. I have taken the ZTM Python course and i have came down till here. Today i tried these 3 questions out of which i cant solve even one of them. Could anyone please tell me if i am into the right direction of my career or not. I mean is it normal for person to not solve any of these simplest question

Indeed not normal. But it's OK. Don't let it stop you. You just found something new to learn. Keep on keeping on.

@mishrasunny-coder
Copy link

Hello.
I am new to the python coding.
I have taken the ZTM Python course and i have came down till here. Today i tried these 3 questions out of which i cant solve even one of them.
Could anyone please tell me if i am into the right direction of my career or not. I mean is it normal for person to not solve any of these simplest question

Do not worry!!! Did you solve exercises on your own without looking at the solution? If not, you should!! You will fail once or twice but then you will get a gist of how to approach a problem!! It’s normal!! Don’t let it stop keep going!!

@honcyeung
Copy link

Hello. I am new to the python coding. I have taken the ZTM Python course and i have came down till here. Today i tried these 3 questions out of which i cant solve even one of them. Could anyone please tell me if i am into the right direction of my career or not. I mean is it normal for person to not solve any of these simplest question

It is normal that when you start coding, you can't immediately solve the questions. As long as you keep practising, you will get there. Dont give up. We have experiences what you have been through

@UtsavBhamra
Copy link

UtsavBhamra commented Jul 20, 2023

#Could this be another solution for q6?

x = input()

y = x.split(",")

my_list = []

for number in y:
D = int(number)
Q = (250D)/30
my_list.append(Q**0.5)

for item in my_list:
print(round(item),end = ',')

#i have directly put the values of C and H instead of using the variables.

@SevenKkkkkkk
Copy link

捉虫,最后的conclusion里单词写错嘞,是syntax句法,不是syntex

@SevenKkkkkkk
Copy link

捉虫,Question 7 note里的j,省略号不对,怎么成小i了

@SevenKkkkkkk
Copy link

捉虫,最后的conclusion里单词写错嘞,是syntax句法,不是syntex

第一天的conclusion

@SevenKkkkkkk
Copy link

有地方写错了应该,Q49 hints:To override a method in super class, we can define a method with the same name in the super class.应该是To override a method in super class, we can define a method with the same name in the sub class.在子类中定义才对吧

@SevenKkkkkkk
Copy link

q50 hints:UUse 多打了个U

@rayq1612
Copy link

It can be solution of question 3. Five brackets in the end of line two, bruh. But it's two line solution : )

i = int(input('Number?\n'))
print(dict(zip(range(1, i + 1), map(lambda item : item ** 2, range(1, i + 1)))))

@rayq1612
Copy link

One string solution for question16:
print(",".join([str(int(item)**2) for item in input().split(',') if int(item) % 2 == 0]))

@MarkisLandis
Copy link

MarkisLandis commented Sep 26, 2023 via email

@imyuanhui
Copy link

it can be solution of question 1:

def find_numbers():
    num = ""
    for n in range(2000, 3200):
        if n % 7 == 0 and n % 5 != 0:
            num += f"{n}, "
    num = num.rstrip(", ")
    print (num)

@imyuanhui
Copy link

imyuanhui commented Dec 31, 2023

i made some changes of solution by @minnielahoti to question 2:

def fact_with_input():
    while True:
        try:
            n = int(input("Enter a number: "))
            assert n > 0  #n must be positive
            break
        except AssertionError:
            print("Please input a positive number") #give a hint if the input is not positive
        except ValueError:
            print("Please input an integer") #give a hint if the input is not an integer
    result = 1
    for i in range(1, n+1):
        result *= i
    print(result)

@imyuanhui
Copy link

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

@Euan-J-Austin
Copy link

Euan-J-Austin commented Dec 31, 2023

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='')

@Euan-J-Austin
Copy link

I thought this was a neat solution to Question 96 that doesn't require textwrapper...

s, w = input("ENTER STRING: "), int(input("ENTER WIDTH: "))

i = 0

while i < len(s):
  print(s[i:i+w])
  i += w

@mirohhinkov
Copy link

mirohhinkov commented Dec 31, 2023 via email

@imyuanhui
Copy link

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!!!

@imyuanhui
Copy link

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!!

@Fatma-Nur-Azman
Copy link

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

@Fatma-Nur-Azman
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests