Kaggle Challenge 03 - Functions and Getting Help

JongseokLee·2021년 8월 6일
0
post-thumbnail

Kaggle Challenge 03 - Functions and Getting Help

0. help()

I saw the abs function in the previous tutorial, but what if you've forgotten what it does?

Example : help(round)

Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.
    
    The return value is an integer if ndigits is omitted or None.  Otherwise
    the return value has the same type as the number.  ndigits may be negative.

1. Question01(round)

Problem

def round_to_two_places(num):
    """Return the given number rounded to two decimal places. 
    
    >>> round_to_two_places(3.14159)
    3.14
    """
    # Replace this body with your own code.
    # ("pass" is a keyword that does literally nothing. We used it as a placeholder
    # because after we begin a code block, Python requires at least one line of code)
    pass
    round(3.14)

# Check your answer
q1.check()

help(round)

Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.
    
    The return value is an integer if ndigits is omitted or None.  Otherwise
    the return value has the same type as the number.  ndigits may be negative.

Solution

return round(num, 2)

2. Question02

Problem

The help for round says that ndigits (the second argument) may be negative. What do you think will happen when it is? Try some examples in the following cell.

Solution

Solution: As you've seen, ndigits=-1 rounds to the nearest 10, ndigits=-2 rounds to the nearest 100 and so on. Where might this be useful? Suppose we're dealing with large numbers:

The area of Finland is 338,424 km²
The area of Greenland is 2,166,086 km²

We probably don't care whether it's really 338,424, or 338,425, or 338,177. All those digits of accuracy are just distracting. We can chop them off by calling round() with ndigits=-3:

The area of Finland is 338,000 km²
The area of Greenland is 2,166,000 km²

(We'll talk about how we would get the commas later when we talk about string formatting :))

3. Question03

Problem

In the previous exercise, the candy-sharing friends Alice, Bob and Carol tried to split candies evenly. For the sake of their friendship, any candies left over would be smashed. For example, if they collectively bring home 91 candies, they'll take 30 each and smash 1.
Below is a simple function that will calculate the number of candies to smash for any number of total candies.
Modify it so that it optionally takes a second argument representing the number of friends the candies are being split between. If no second argument is provided, it should assume 3 friends, as before.
Update the docstring to reflect this new behaviour.

def to_smash(total_candies):
    """Return the number of leftover candies that must be smashed after distributing
    the given number of candies evenly between 3 friends.
    
    >>> to_smash(91)
    1
    """
    return total_candies % 3

# Check your answer
q3.check()

Solution

def to_smash(total_candies, n_friends=3):
    return total_candies % n_friends
profile
DataEngineer Lee.

24개의 댓글

comment-user-thumbnail
2022년 8월 10일

This is a fantastic post, and I appreciate the details. Without a doubt, education is a sensitive subject. Despite this, one of the hottest topics of our time remains. I enjoy reading your posts and look forward to reading more. uno online

답글 달기
comment-user-thumbnail
2023년 7월 27일

Great information! I will visit your site more often so I am updated. The ideas I gather from here cannot be paid with money. Thanks very much! Bitlife

답글 달기
comment-user-thumbnail
2024년 3월 23일

I am very happy to discover your post as it will become on top in my collection of favorite blogs to visit Strands Unlimited https://strandsgame.net/

답글 달기
comment-user-thumbnail
2024년 3월 27일
답글 달기
comment-user-thumbnail
2024년 3월 30일

Thank you for submitting this article. This is information I have been looking for. I’ve been hoping to find clear and concise content like yours. Your unique points helped me think about this information differently. Not My Neighbor Online https://notmyneighborgame.com/

답글 달기
comment-user-thumbnail
2024년 6월 14일

Sometimes, we have to travel to a remote area or want to make the journey enjoyable. In such situations, Pikashow also offers a cool feature for downloading. You can download and save your favorite movies, series, or drama and then can enjoy these downloaded media while traveling when you get out of an internet connection. This is an incredibly amazing feature also by, users can enjoy a smooth experience of their favorite content if they run out of poor internet connection. https://pikashowhd.net.in/

답글 달기
comment-user-thumbnail
2024년 8월 23일

Just by downloading this Lucky Patcher APK on your Android device, you will have access to all of the premium features of the Games and Apps. This means now you can collect more and more coins without payments and get to the next level in games or you will not face advertisement issues during the use of apps and many more features of any game or app that are premium. https://luckypatcher.com.in/

답글 달기
comment-user-thumbnail
2024년 9월 15일

Great insights on tackling Kaggle challenges! It's always exciting to dive deep into data and find patterns. When I need a break from coding and analytics, I often switch to watching movies or TV shows. Recently, I discovered FreeCine, which offers a wide selection of content. If you're looking for something to relax with after long hours of work, I suggest checking out baixar FreeCine. It’s been a great way to unwind while staying productive!

답글 달기
comment-user-thumbnail
2024년 9월 15일

Ótimas dicas para enfrentar os desafios do Kaggle! Sempre é empolgante mergulhar nos dados e encontrar padrões. Quando preciso de uma pausa do código e das análises, costumo relaxar assistindo filmes ou séries. Recentemente, descobri o FreeCine, que oferece uma grande variedade de conteúdos. Se você está procurando algo para relaxar depois de horas de trabalho, recomendo dar uma olhada em baixar FreeCine. É uma ótima forma de descontrair e se preparar para o próximo desafio!

https://freecineappk.com/

답글 달기
comment-user-thumbnail
2024년 10월 25일

Welcome to the exhilarating world of Word500, where your linguistic prowess is put to the ultimate test! To dive into this thrilling game, gather a group of word enthusiasts and equip yourselves with a timer set for five minutes. Each player scribbles down as many words as they can think of that start with the letters from A to Z—yes, you heard it right! https://nytwordle.today/word500/

답글 달기
comment-user-thumbnail
2024년 10월 25일

Sometimes, we have to travel to a remote area or want to make the journey enjoyable. In such situations, Pikashow also offers a cool feature for downloading.https://pikashowapp.com.in/

답글 달기
comment-user-thumbnail
2024년 11월 1일

By clicking on the download button, you may see a warning when trying to download the Honista application. But you have to skip this word and complete the process of downloading the Honista application, and after completion, open the application on your phone.https://honistaapk.net/

답글 달기
comment-user-thumbnail
2024년 11월 6일

9anime is the best free anime streaming website where you can watch English Subbed and Dubbed anime online. WATCH NOW! No Ads GUARANTEED!
https://9animes.mom/

답글 달기
comment-user-thumbnail
2024년 11월 6일

Aniwave, formerly known as 9anime, is the best website to watch anime online for free, watch anime with DUB, SUB in HD. WATCH NOW! No Ads GUARANTEED!
https://aniwave.com.pl/

답글 달기
comment-user-thumbnail
2024년 11월 6일

Animesuge is an awesome network of 2024 to watch free anime online in english dub and sub for free.
https://animesuges.mom/

답글 달기
comment-user-thumbnail
2024년 11월 6일

After reading your article I was amazed. I know that you explain it very well. And I hope that other readers will also experience how I feel after reading your article.
Sprunki Mod https://sprunkin.com/

답글 달기
comment-user-thumbnail
2024년 11월 21일

This is also a very good post which I really enjoyed reading. It is not every day that I have the possibility to see something like this.. Block Blast Solver https://blockblastsolver.org/

답글 달기
comment-user-thumbnail
2025년 1월 6일

nice aetcler.

답글 달기
comment-user-thumbnail
2025년 1월 6일

Obrigado pelas amáveis ​​​​palavras! Mergulhar nos desafios do Kaggle é uma maneira fantástica de melhorar suas habilidades de análise de dados. Depois de um longo dia codificando e analisando dados, muitas vezes mudo de assunto e gosto de filmes ou programas de TV. Recentemente, descobri o FreeCine, que oferece uma biblioteca diversificada de conteúdo perfeita para relaxar. Se você está procurando uma maneira de relaxar depois do trabalho e ao mesmo tempo permanecer produtivo, considere explorar https://freecinebr.com. É uma ótima plataforma para transmitir conteúdo sem comprometer a qualidade.

답글 달기
comment-user-thumbnail
2025년 1월 22일

Thanks for your Article, I learn more.
I create a online tool to create Pokemon TCG Pocket Decks, webcome to try it https://tcgpdecks.com

답글 달기
comment-user-thumbnail
2025년 1월 24일

Find the latest working Haikyuu Legends codes here. All codes are tested and verified daily.
https://haikyuulegendscodes.com/

답글 달기
comment-user-thumbnail
2025년 1월 26일

Having a blast cruising through escape road 2 tonight! This track is seriously gorgeous, and I'm loving the scenery while I'm burning rubber (and probably crashing a few times, haha). Anyone else in the mood for some friendly races? Hit me up if you want to go head-to-head and see who's the ultimate driver. Let the chaos begin!

답글 달기
comment-user-thumbnail
2025년 1월 26일

I think my brain just had a pyramixed explosion trying to keep up with this song. The sprunki synths were bouncing all over the place, and I swear the parodybox drum samples were mocking my lack of rhythm! But honestly, I'm loving every second of this chaotic masterpiece! Send help (and practice tips)!

답글 달기
comment-user-thumbnail
2025년 1월 29일

Convert letters to numbers or numbers to letters is extremely easy with this online tool.

답글 달기

관련 채용 정보