break-the-ice-with-python icon indicating copy to clipboard operation
break-the-ice-with-python copied to clipboard

Query, Discussion & Bug Report

Open darkprinx opened this issue 6 years ago • 218 comments

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 avatar Jan 16 '19 21:01 darkprinx

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)

Amitewu avatar Apr 16 '19 15:04 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)

Added. Thank you :)

darkprinx avatar Apr 17 '19 07:04 darkprinx

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

Amitewu avatar Apr 19 '19 15:04 Amitewu

Just check whether the input is empty or not.

darkprinx avatar Apr 19 '19 18:04 darkprinx

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

sam1037 avatar Jul 22 '19 10:07 sam1037

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

darkprinx avatar Jul 22 '19 17:07 darkprinx

Thank you for teaching me.

sam1037 avatar Jul 23 '19 09:07 sam1037

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

Amitewu avatar Jul 29 '19 16:07 Amitewu

#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

darkprinx avatar Jul 29 '19 18:07 darkprinx

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

ArturOle avatar Sep 17 '19 12:09 ArturOle

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.

darkprinx avatar Sep 18 '19 15:09 darkprinx

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

dwedigital avatar Oct 22 '19 12:10 dwedigital

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

darkprinx avatar Oct 22 '19 17:10 darkprinx

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.

leonedott avatar Nov 01 '19 13:11 leonedott

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.

darkprinx avatar Nov 01 '19 14:11 darkprinx

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

leonedott avatar Nov 03 '19 12:11 leonedott

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.

darkprinx avatar Nov 03 '19 17:11 darkprinx

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

vibhu077 avatar Nov 06 '19 17:11 vibhu077

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

MarkisLandis avatar Nov 06 '19 17:11 MarkisLandis

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 avatar Nov 07 '19 16:11 darkprinx

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

darkprinx avatar Nov 07 '19 16:11 darkprinx

Can you please give me more question from topics

On Wed, 6 Nov 2019, 11:22 p.m. MarkisLandis <[email protected] wrote:

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

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/darkprinx/100-plus-Python-programming-exercises-extended/issues/3?email_source=notifications&email_token=ANMX5BM77LHPDDZTHLMYFALQSL74VA5CNFSM4GQP6TLKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEDHNHEI#issuecomment-550425489, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANMX5BMDAPR2DRK22XJVDJLQSL74VANCNFSM4GQP6TLA .

vibhu077 avatar Dec 04 '19 11:12 vibhu077

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 avatar Dec 22 '19 03:12 yuan1z

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

yuan1z avatar Dec 22 '19 03:12 yuan1z

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

Both solutions are added. Thank you :)

darkprinx avatar Dec 22 '19 05:12 darkprinx

Question #60 The problem statement should be f(0) = 0, otherwise f(5)=501

yuan1z avatar Dec 22 '19 23:12 yuan1z

Question #67 Recursion method

idx = 0 def bs(num,num_list): global idx if (len(num_list) == 1): if num_list[0] == num: return idx else: return "No exit in the list" elif num in num_list[:len(num_list)//2]: return bs(num,num_list[:len(num_list)//2]) else: idx += len(num_list)//2 return bs(num,num_list[len(num_list)//2:]) print(bs(5,[1,5,8,10,12,13,55,66,73,78,82,85,88,99,100]))

yuan1z avatar Dec 23 '19 20:12 yuan1z

@yuan1z Contributions are added. Thank you. :)

darkprinx avatar Dec 24 '19 15:12 darkprinx

Question 2, Method 3 (recursive function) needs a little correction because in case if input 0 the function throw an error but 0! is defined as 1: The solution is return 1 if x less or equal to 1:

`n = int(input())
def shortFact(x): return 1 if x <= 1 else x*shortFact(x-1)
print(shortFact(n))`

StartZer0 avatar Dec 25 '19 02:12 StartZer0

@StartZer0 The bug has been fixed. Thanks for your cooperation :)

darkprinx avatar Dec 25 '19 05:12 darkprinx