darkprinx / break-the-ice-with-python Goto Github PK
View Code? Open in Web Editor NEWThe repository is about 100+ python programming exercise problem discussed, explained, and solved in different ways
The repository is about 100+ python programming exercise problem discussed, explained, and solved in different ways
Describe the bug
Question 15 solutions not producing the correct output (except for the Python 2 solution which is correct)
To Reproduce
Paste the solutions in your editor of choice and run the code
Expected behavior
For input '9' I expected a result of 11106
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
n/a
Smartphone (please complete the following information):
n/a
Additional context
The Python 2 solution is correct
The first Python 3 solution does not run and returns error:
tmp+=a # concatenating 'a' to 'tmp'
TypeError: can only concatenate str (not "int") to str
The second Python 3 solution returns 90 instead of 11106
The solution by ChichiLovesDonkeys does not have a print statement. Even with that it outputs 90 instead of 11106.
The solution by lcastrooliveira returns 90 instead of 11106
The solution by apenam7 returns 90 instead of 11106
I think in all these instances not casting the user input digit to a string is the source of the problem. The solution I devised gives the correct answer of 11106.
a = input("Enter a digit ")
print(sum([int(str(a) * i) for i in range(1,5)]))
print({num: num**2 for num in range(1, int(input('Enter the number : ')) + 1)})
binary_numbers = input('Write a sequance of comma and whitespace(, ) separated 4 digit binary numbers(0,1): ').split(', ')
for number in binary_numbers:
value = 1
res = 0
for digit in number[::-1]:
res += int(digit) * value
value *= 2
# print(res)
if (res % 5) == True:
binary_numbers.remove(number)
print(', '.join(binary_numbers))
print(bool(4 % 5))
print(bool(3 % 5))
print(bool(10 % 5))
print(bool(9 % 5))
True
True
False
True
ml = ['asdasd', 'dfdffdf', 'ssdsdfsdfsdfsdfdfdfddd', 'asdasdasdssssss']
for item in ml:
print(item, len(item))
if len(item) > 6:
ml.remove(item)
asdasd 6
dfdffdf 7
asdasdasdssssss 15
['asdasd', 'ssdsdfsdfsdfsdfdfdfddd']
ml = ['asdasd', 'dfdffdf', 'ssdsdfsdfsdfsdfdfdfddd', 'asdasdasdssssss']
for item in ml:
print(item, len(item))
# if len(item) > 6:
# ml.remove(item)
asdasd 6
dfdffdf 7
ssdsdfsdfsdfsdfdfdfddd 22
asdasdasdssssss 15
def factorial(num):
if num == 1:
return 1
else:
return `num` * factorial(num - 1)
New Solution Proposal:
I see that none of the solutions listed used a dictionary to store the "deposit" and "withdraw". I solved it using a dictionary and I'd like to see this perspective of solution added. You can check out my fork/PR.
in this program every second string is being saved and every odd string is skipped.
Solution:
change while input(): to while True: and it will be solved like below:
lst = []
while True:
x = input()
if len(x) != 0:
lst.append(x.upper())
else:
break
print(lst)
for line in lst:
print(line)
#53
c=[]
account = input('please enter the username : ')
for i in account :
c.append(i)
if i == '@':
break
print("".join(c[0:c.index(i)]))
When we use more than 2 duplicates than the program gives us an incorrect solution. the program only works on 2 duplicates. so I think we need to use a While loop instead of if statement.
import math
number = input("Enter a number: ")
factorial = math.factorial(int(number))
print(factorial)
Hello,
I am looking for the most efficient way of writing a program of array with binary values (0s and 1s) to find a row with max number of 1s.
For example if row 3 has max 1s then output should print row = 3
import re
lst = input().split(',')
for thing in lst:
if re.search('[a-zA-Z0-9][/#/&/@]', thing) and len(thing) >= 6 and len(thing) <= 12 :
print(thing)
for i in range(n+1): a=1 a=a*(i+1)
With the above method, factorial can be calculated. With this method, it is easier to understand the algorithm
For Question 3:
def integral(num):
temp_list=[item for item in range(1, num)]
return { item: item*item for item in temp_list}
inputs = int(input("Please a number"))
integral(inputs)
I would like to add alternate solution to question 2 of Day 1 using lambda functions.
num = input().split(",")
for i in num:
if int(i,2)%5==0:
print(i)
Problem: As a Python user, I find that many of the examples and tutorials available online focus on specialized use cases or theoretical concepts rather than practical day-to-day applications.
Solution: I would like to see more resources, such as blog posts, tutorials, and sample code, that showcase how Python can be used in real-world scenarios. For example, code snippets that demonstrate how to automate repetitive tasks, analyze data from common file formats (such as CSV or Excel), or interact with popular web APIs (such as Twitter or Google Maps).
Alternatives: While there are some resources available that cover these topics, they can be difficult to find among the sea of more specialized content. Additionally, many existing resources assume a certain level of expertise and technical knowledge, which can be intimidating for beginners or casual users.
Additional context: By highlighting these practical applications of Python, we can make the language more accessible and appealing to a wider audience. This could help attract new users and foster a more diverse and inclusive community of Python developers.
class divisible :
def by_seven(self,n):
for number in range(0,n+1):
if number % 7 == 0 :
print(number)
divisible=divisible()
generator = divisible.by_seven(int(input("please enter the number : ")))
c = 50
h = 30
d = (100, 150, 180)
d = [int(i) for i in d.split(',')]
z =[]
for i in od:
x = 2cd[i]
y = x/h
q = round(y**0.5)
z.append[q]
I can not understand why I can not convert this is d in to a list ??? how ever others can do it ? with same statement
In the last solution, the variable "digit" is mistakenly spelt as "digits". Should be an easy fix.
lst=[1,2,3,4,5,6,7,8,9]
a=list(filter((lambda x : x%2 !=0),lst))
a=list(map((lambda a:a**2),a))
print(a)
Hello,
I am looking for the most efficient way of writing a program of array with binary values (0s and 1s) to find a row with max number of 1s.
For example if row 3 has max 1s then output should print row = 3
Question 9:
Write a program that accepts sequence of lines as input and prints the lines after making all characters in the sentence capitalized.
Suppose the following input is supplied to the program:
Hello world
Practice makes perfect
My answer is given below:
x = input()
print(str(x).upper())
num = int(input())
result = {}
for i in range(1, num + 1):
result.setdefault(i, i * i)
i += 1
print(result)
It says to the program should print a comma-separated sequence yet it also says (and as we all know with common sense) that output should just a single integer. So should we correct it to the "program should print the single integer result" or something like this?
'''Solution by: parian5
'''
from math import sqrt
C, H = 50, 30
mylist = input().split(',')
print((round(sqrt(2C*int(D)/H)) for D in mylist), sep=",")
'''Solution by: Utkarsh4697
'''
from math import sqrt
C, H = 50, 30
mylist = input().split(',')
print((round(sqrt(2C*float(D)/H)) for D in mylist), sep=",")
1.Notebook 07, Question 21:
if s[0] == "UP":
x -= int(s[1]) -> y+=
if s[0] == "DOWN":
x += int(s[1]) -> y-=
if s[0] == "LEFT":
y -= int(s[1]) -> x-=
if s[0] == "RIGHT":
y += int(s[1]) -> x+=
2.Noteboook 17, Question 67, at first solution:
print("Middle value:", x) -> print("Middle index:", x)
Each letter and digit we use has a corresponding unique Unicode integer value. We can get this value using Python's built-in ord() function. Knowing which integers represent upper- and lower-case letters, which represent the digits 0 through 9 we can then use the len() function and list comprehension to determine the number of letters and digits. My solution avoids unwieldy if else conditions etc.
Thoughts?
def count_ld(x):
return print(f'LETTERS {len([v for v in x if ord(v) in range(65, 91) or ord(v) in range(97,123)])}\nDIGIT {len([v for v in x if ord(v) in range(48,54)])}')
count_ld(input("ENTER: "))
First, of all, I would like to thank you for creating this valuable resource and others for contributing.
Concerning Question 9, neither of the provided solutions produces the output specified in the question:
Solution 1 does not work because the program is exited before the input is appended to the list.
lst = []
while input():
x = input()
if len(x) == 0:
break
lst.append(x.upper())
for line in lst:
print(line)
Solution 2 works in part. The user can enter a single line and a capitalized line is returned. This is not the output specified in the solution. Moreover, there's no way to break from the code without initiating an EOFError using ctrl+d/z.
def user_input():
while True:
s = input()
if not s:
return
yield s
for line in map(str.upper, user_input()):
print(line)
I believe my solution gives the output specified in Question 9, with the empty line separating the two.
lines = []
print("Enter your text, when finished type 'end_and_print':\n")
while True:
line = input()
if line != 'end_and_print':
lines.append(line)
else:
break
print('\n'.join(lines).upper())
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.