Back

Sanskar

Keen Learner and Exp... • 1m

Day 5 of learning python as a beginner. Topic: Functions On my previous day post many people shared their github where I was introduced to def functions and since then I started learning more about def functions. Thank you all those people who are supporting and guided me. def functions are user defined functions which you can reuse in your code again and again without repeating the logic. Python has two types of functions pre-defined (ex- sum(), max(), etc) and user-defined (which user creates himself think of it like reusable components). I have created a unit converter using def function. First I have created reusable code logic for conversion formulas. I have used replace in place of print because it shows result on screen (console output) and will return "none" when called in the def function however on the other hand return sends the result back to the caller (which can be used later). Then I have let user enter a number (without unit) and then the unit seperately (if user put unit in the first input then it will be treated as a string and formulas will not work, thus giving an error). Then I used a list directly in if else statement (I didn't know that list can also be used directly in if else) and I created 4 such lists of different units so that any one condition can become true in if elif and else table. I hope I am able to explan this code without making it complex. I would appreciate any challenge or suggestion to improve my code. And here's my code and it's result.

Reply

More like this

Recommendations from Medial

Image Description

Hari Krishna

Developer | entrepre... • 5d

Day6/100: • def —> Creating a function ( user defined) def name(): Condition Name() —> calling the function 🤙🏻 ————— Likewise we can create a library 📚 in python 🐍 • import ( the file we created ) ————— Today played with Reeborg rob

See More
2 Replies
8

Sanskar

Keen Learner and Exp... • 18d

Day 30 of learning python as a beginner. Topic: making a fully functional calculator. Yesterday I got introduced to tkinter and was successful in creating a basic graphical layout for the calculator and today I added logic into it and now I finally

See More
Reply
2

Sanskar

Keen Learner and Exp... • 1m

Day 17 of learning python as a beginner. Topic: lambda functions + email filter Lambda functions are a single line anonymous function without using the usual def key word. All function: checks whether all the key words (spam_keywords) are present

See More
Reply
2

Vansh Khandelwal

Full Stack Web Devel... • 9m

Unit testing is a critical practice in software development that ensures individual code units work as expected. It helps catch bugs early, simplifies refactoring, and improves code quality and reliability. Unit tests verify the smallest parts of an

See More
Reply
2

Sanskar

Keen Learner and Exp... • 24d

Day 24 of learning python as a beginner. Topic: decorators Somebody has suggested me that I should focus on some of the important things and he gave me a list of topics to learn. Decorators were at very top of that list and therefore I decided to l

See More
Reply
1
Image Description
Image Description

Arpit Shukla

Helping people achie... • 1m

Why are we still coding in programming languages when plain but exact English statements should be used to define what functions and methods should do. Just a vision: 1. Let everyone (not only developers) write modular functions with plain English d

See More
8 Replies
14

Sanskar

Keen Learner and Exp... • 1m

Day 11 of learning python as a beginner. Topic: creating journal entry program using file I/O. I got a little sidleline from my original plan of editing my to-do list program and created an entirely new program this time for writing a daily journal

See More
Reply
1
10

Sanskar

Keen Learner and Exp... • 25d

Day 23 of learning python as a beginner. Topic: multi-threading. Multi-threading is a technique to run multiple task (such as importing or downloading) within a single program and at the same time. Thus running multiple things parallelly, in a nuts

See More
Reply
2
Image Description

Sanskar

Keen Learner and Exp... • 1m

Day 7 of learning python as a beginner. Topic: making a dynamic to-do list. Yesterday I created a basic to-do list and some people suggested and gave me a challenge that I should make it more dynamic so that the user can choose the day where he wan

See More
3 Replies
1
5

Sanskar

Keen Learner and Exp... • 20d

Day 28 of learning python as a beginner. Topic: web scraping with postgreSQL database. When I posted my first web scraping project I just had the result on console however I wanted it to be stored somewhere where it can be reviewed later that's whe

See More
Reply
1

Download the medial app to read full posts, comements and news.