Am I Making Progress in Learning Python?

0
8
Asked By CuriousCoder42 On

I've just started learning Python and wanted to share my code from the first few days to see if I'm on the right path. Here's what I've got so far:

On my first day, I wrote a simple calculator function that takes two numbers as input and prints their sum:
```python
def calc():
first = float(input("nEnter first number: "))
second = float(input("Enter second number: "))
result = first + second
print(f"nOkay people, now your count is {result}")

def main():
print("Hello, Man")
calc()

if __name__ == "__main__":
main()
```

On my third day, I shifted gears and wrote a checklist program that handles adding, deleting, and displaying items:
```python
#!/usr/bin/python3
from os import system, name

buffer = "--NONE--"

def clear():
system('cls' if name == 'nt' else 'clear')

def Add():
global buffer
if buffer == "--NONE--":
buffer = input("Your case: ")
else:
buffer += "n"
buffer += input("Your case: ")
print("ADDED")
clear()
Do()

def Delete():
global buffer
buffer = "--NONE--"
print("DELETED")
clear()
Do()

def Exit():
clear()
exit()

def __init__():
print(f"n{buffer}")

def Display():
print("||==============================================||")
print("||===============CheckList-0.1v=================||")
print("||==============================================||")
__init__()
Do()

def Do():
print("n[1] - Add [2] - Delete [3] - Display [4] - Exit")
do = int(input("What you do? "))
if do == 1:
Add()
elif do == 2:
Delete()
elif do == 3:
Display()
elif do == 4:
Exit()
else:
print("What?")
Do()

def main():
Display()

if __name__ == "__main__":
main()
```

I'd love to hear any feedback about my work so far!

5 Answers

Answered By DevDude On

It’s awesome that you're practicing coding! However, be careful with using 'global' in your checklist script. It's usually not the best practice and could complicate your code later on. Also, I recommend naming your functions and classes in a way that's more conventional to make your code easier to read.

Answered By LearningInPublic On

I think it's great that you're exploring functions! Just a heads up though, your third day code seems a bit complex for the task; recursion isn’t really needed here, which could lead to issues if you stack calls too deep. Instead, a simple loop would keep your program running smoothly.

Answered By TechyTommy On

Your first day code looks solid for a beginner! It’s simple and gets the job done without unnecessary complexity. For your day three code, try avoiding the global keyword if possible; it can lead to harder-to-maintain code. Also, instead of recursion to handle the menu, using a loop would be a cleaner approach— like a while loop that runs until you choose to exit.

Answered By CodeLover99 On

Overall, keep it up! Your first day code is clearly set up. The third day code could use some improvement in terms of readability and organization, but it’s impressive for a quick learning process. Functions are definitely the way to go to keep building your skills!

Answered By CodeCritique21 On

Just to point out, your functions on day one and day three don't return anything. I'd suggest thinking about whether that's what you intend. You could return values from your functions to make them more useful.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.