Code Monkey home page Code Monkey logo

break-the-ice-with-python's Introduction

Hello there ๐Ÿ‘‹ It's Tushar ๐Ÿ˜ƒ

Software Engineer ๐ŸŒฑ Mindful Explorer ๐ŸŒฑ Ambivert


break-the-ice-with-python's People

Contributors

aasaialangaram avatar anjankumarg avatar apenam7 avatar apurvmishra99 avatar danzvara avatar darkprinx avatar harshraj22 avatar jiaming9844 avatar minnielahoti avatar nikuksh avatar poonam-glitch avatar prash099 avatar pratikb0501 avatar renatolopes771 avatar shagunattri avatar sophiexsun avatar suggulajaswanth avatar sukanya-mahapatra avatar ulmasovjafarbek avatar utkarsh4697 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

break-the-ice-with-python's Issues

Question 15 solutions not producing the correct output

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

Question 11 "for loop | if statement" problem

Why this code behave in such a strange way?

Here is the problem:

Write a program which accepts a sequence of comma separated 4 digit binary numbers as its input and then check whether they are divisible by 5 or not. The numbers that are divisible by 5 are to be printed in a comma separated sequence.

Example:

0100,0011,1010,1001

Then the output should be:

1010

Notes: Assume the data is input by console.

Here is my solution:

resultat equals to sum of values, multiplied by their symbols

values start from 1 and doubles for each next symbol

symbols can be only 1 or 0

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

so, if we print out "res"s, with "0100, 0011, 1010, 1001" as input, we would have 4, 3, 10, 9 as output

and out for:

print(bool(4 % 5))
print(bool(3 % 5))
print(bool(10 % 5))
print(bool(9 % 5))

will be:

True
True
False
True

so, it should work, but it doesn't

I assumed, that problem is in the list removing and wrote this piece of code:

ml = ['asdasd', 'dfdffdf', 'ssdsdfsdfsdfsdfdfdfddd', 'asdasdasdssssss']

for item in ml:
print(item, len(item))
if len(item) > 6:
ml.remove(item)

and, all of a sudden, it doesn't work too, the output is:

asdasd 6
dfdffdf 7
asdasdasdssssss 15
['asdasd', 'ssdsdfsdfsdfsdfdfdfddd']

but length of the third(2) item of a list is obviously bigger than 6, so, looks like this code has been completely skipping the 'ssdsdfsdfsdfsdfdfdfddd' value. Further more, if we comment out the "if" block, it will see this value in the list and print its length

in:

ml = ['asdasd', 'dfdffdf', 'ssdsdfsdfsdfsdfdfdfddd', 'asdasdasdssssss']

for item in ml:
print(item, len(item))
# if len(item) > 6:
# ml.remove(item)

out:

asdasd 6
dfdffdf 7
ssdsdfsdfsdfsdfdfdfddd 22
asdasdasdssssss 15

I completely don't inderstand what is going on between for loop and conditional if statement.

Is anybody knows?

Day 5 Q17

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.

Day 2 Question 9

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:

Why do every second line is storing in the list and all odd lines are skipped?

lst = []

while True:
x = input()
if len(x) != 0:
lst.append(x.upper())
else:
break

print(lst)
for line in lst:
print(line)

I got a error in Que 10 Python 3 Solution.

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.

Another solution for Q18

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)

Fact algoritm

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

Day 1 , Question 3 Enhancement

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)

[Request: Real world application]

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.

hello dear about question 20 i have an idea

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

qs 6

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

Need help with writing a program in Python

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

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.

Question 9:

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

Q2 Wording

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?

I Found a mistake in Question 06 (Solution by: parian5)

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

Some errors

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)

Q14 Improved Solution

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

Correct solution to Question 9

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.