Back

Sanskar

Keen Learner and Exp... • 14h

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

Vansh Khandelwal

Full Stack Web Devel... • 7m

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
Image Description
Image Description

Arpit Shukla

Helping people achie... • 14d

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
Image Description
Image Description

Aurobindo Patra

ezeslucky • 1y

I use VS Code. I have always used it. And never really considered switching. Is that wrong? What do you use?

3 Replies
1
2

Shubham Kumar

Hey I am on Medial • 6m

i have lot of successful and tested ayurvedic formulas but i need a team to support me and financiers too how can i get the right team?

Reply
3

Divyansh Maurya

Building present, li... • 6m

[This post has been deleted by the creator]

Reply
3
Image Description

Dileep Kadiveti

IoT Student with a C... • 1y

[This post has been deleted by the creator]

1 Reply
4

Prasad Balasaheb Adhagale

I will make myself • 2m

Hello, I want to open the steel pipe manufacturing unit. Which products are used in furniture staircases and curtain pipes which have very demanding products. if any investor is interested please reply to me I will explain all the plan

See More
Reply
2

Prasad Balasaheb Adhagale

I will make myself • 2m

Hello, I want to open the steel pipe manufacturing unit. Which products are used in furniture staircases and curtain pipes which have very demanding products. if any investor is interested please reply to me I will explain all the plan

See More
Reply
2
Image Description

Abhishek Patil

Hey I am on Medial • 8m

I am developing sign up page , I have multiple sections such as mobile number password then personal information then other information then images to upload, what if user quits in between sign up process, if user closes tab , then if user revisits

See More
1 Reply
3

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