DEV Community

lordronjuyal
lordronjuyal

Posted on

1

day 7

date: 26 May, 2024.
Importing from module:- To import a module(file) in our code we use: import module_name. But this may increase the size of our file. If we want only one method from the module we can use: from module import function_name. It will only import that function from the module file.

Other things I learned:

  1. from os import system -- If we require to clear the console screen when the program is running we can import this and use: system("clear")

  2. Docstring -- We can create documentation of our user-defined function using this. Just after the first line of function definition[def func_name():], use multiple line string("""... """") to write what function does, variables it can take, etc. Now whenever we call this function the user can see this comment on hovering over that function call.

  3. We can use dictionary to store function names.
    eg def func1:
    .....
    def func2:
    .....
    dic= { key1 : func1, #no () so it won't call the function
    ....
    variable1=dic[key1]
    this will copy the function into variable1 and we can use
    variable1()

  4. Recursion - this is a process in which function keeps on calling itself and the process continues. It is just like a while loop. So we need to have a termination condition in it.

  5. for index, item in enumerate(list):
    Above is the for loop by which we can get the item and their index value in the list. Otherwise, we have to use another variable =0 and +1 in each iteration.

  6. We can't call a function before we define it.

Program I made:

  1. Auction app - using dictionary
    auction app using dictionary

  2. Calculator app
    https://replit.com/@rohitrj332024/Calculator#main.py

  3. Blackjack -This took much of my time. But I am happy I completed it without watching the tutorial. Code may not be proper but I tried my best to use functions and comments to help myself in future. Making flowchart in advance and breaking program into smaller problems helped me a lot. I hope with practice I will improve more.

https://replit.com/@rohitrj332024/blackjack-day-7#main.py


Personal --> Coding the project took much of my time. I wanted to jump fast but I think consistency matters more. I am happy that I was able to code a game though my code may be messy or unprofessional, but coding it gave me great satisfaction. Now my brain needs some rest.

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay