break-the-ice-with-python
break-the-ice-with-python copied to clipboard
Query, Discussion & Bug Report
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.
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)
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 :)
In problem 17 How do I terminate this while true condition?????
Just check whether the input is empty or not.
In answer 14, your solution 2, what is '{0}' and '{1}'? I don't understand.
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 :)
Thank you for teaching me.
#This could be the ans for 16 x=input().split(",") ans=list(filter(lambda x : int(x)%2!=0 ,x)) print(",".join(ans))
#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
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:])
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.
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]))
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 :)
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! 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.
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 !!!
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.
Who is the main author plzz telll me sir,@darkprinx
Problem with Question 70. It says random even integer from 0 to 10. 0 is even. But they left it out.
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.
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 :-)
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 .
Answer for Question #30 func = lambda a,b: print(max((a,b),key=len)) if len(a)!=len(b) else print(a+'\n'+b)
Question #34 answer func = lambda :print([i**2 for i in range(1,21)][:5])
Question #34 answer func = lambda :print([i**2 for i in range(1,21)][:5])
Both solutions are added. Thank you :)
Question #60 The problem statement should be f(0) = 0, otherwise f(5)=501
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 Contributions are added. Thank you. :)
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 The bug has been fixed. Thanks for your cooperation :)