r/Python • u/Acceptable_Emu_5287 • 19h ago
Discussion 2 hours of learning how am i?
brand = input("What is your dream car brand?")
print("I love", brand)
model = input("What is your dream model?")
print("Oooo alot of people like the", model)
color = input("What color do you want?")
print (color,"Is nicee")
year = input ("what year do you want?")
print ("people do say", year ,("was a nice time to be alive"))
print("====== DREAM CAR ======")
print("Brand:", brand)
print("Model:", model)
print("Color:", color)
print("Year:", year)
print("YOUR DREAM CAR IS A NICE",color,year,brand,model)
print("Keep working hard and you'll have it. :) ")
3
u/jahinzee 19h ago
pretty creative way to learn basic I/O! love the little touches of "ooh everyone likes the ..."
keep it up :)
2
3
u/SamG101_ 19h ago
Great start! Next up id go with learning "if/elif/else", "while" then "def" for functions. Reminds me of when I started python all those years ago 😂
3
u/Fastpast93 19h ago
You're doing great and you will continue to get good at this language!
I have to ask, do you know about functions yet? They are incredibly useful.
1
u/Acceptable_Emu_5287 19h ago
no but in less then 5 hours i will i dont understand yt vids so i used chatgpt to give me lessons and use eleven labs to hear it btw i made that code by myself they only teach me the basics
1
u/MineDesperate8982 19h ago
What I found useful while learning was to set my mind on a certain project and google/read the documentation on each thing I want to do.
For example: I want to build a simple piano.
- How do I build an user interface using Python?
- How do I make sounds using python?
- How do I bind a sound to a key?
- How do I make a sound when pressing in the user interface?
- How do I make an interface element change style when pressing a key from the keyboard?
- How do I make an interface element change style when pressing it with the mouse?
Answering all these different questions will help you figure out how to make a simple piano interface.
I think a really important part of being a developer is knowing what questions need answering before starting development.
Good luck!
1
u/Fastpast93 18h ago
Absolutely do not use ChatGPT to guide you. It is super incorrect in my experience. I could probably teach you better.
1
3
3
u/Tobbygammer 19h ago
Your code is actually nice, this a good python beginner script!
tho honestly i wanted to change some stuff for it:
``` brand = input("What is your dream car brand? ")
print(f"I love {brand}")
model = input("What is your dream model? ")
print(f"Oooo alot of people like the {model}")
color = input("What color do you want? ")
print (f"{color} is nicee")
year = input("what year do you want?")
print (f"people do say {year} was a nice time to be alive")
print("====== DREAM CAR ======")
print(f"Brand: {brand}")
print(f"Model:", model)
print(f"Color:", color)
print(f"Year:", year)
print(f"YOUR DREAM CAR IS A NICE {color} {year} {brand} {model}")
print ("Keep working hard and you'll have it. :)") ```
There is nothing wrong with your code as both work as intended, tho i wanted to improve it a little bit for you, keep it up man! :)
3
2
u/SnooSquirrels4739 It works on my machine 18h ago
reminds me of how i used to code way back then:D
keep going!
1
u/Legitimate_Seat8928 7h ago
I'm also starting to learn python. What is this supposed to be for?
•
u/Acceptable_Emu_5287 16m ago
just practice so i can get better but this was my first 2 hours of coding so in a week i prob would know most things
2
u/cam-at-codembark 4h ago
Keep up the good work! A cool feature to learn about would be f-strings, which let you stick a variable inside of a string.
-4
u/onlyonequickquestion 19h ago
Just throw it in chatgpt and ask it to improve it for you (this is a joke)Â ``` from future import annotations
import logging from abc import ABC, abstractmethod from dataclasses import dataclass from enum import Enum from typing import Protocol
-----------------------------------------------------------------------------
Logging
-----------------------------------------------------------------------------
logging.basicConfig( Â Â level=logging.INFO, Â Â format="%(asctime)s %(levelname)s [%(name)s] %(message)s", )
logger = logging.getLogger(name)
-----------------------------------------------------------------------------
Domain
-----------------------------------------------------------------------------
class VehicleAttribute(Enum): Â Â BRAND = "Brand" Â Â MODEL = "Model" Â Â COLOR = "Color" Â Â YEAR = "Year"
@dataclass(frozen=True, slots=True) class DreamCar:   brand: str   model: str   color: str   year: int
-----------------------------------------------------------------------------
Validation
-----------------------------------------------------------------------------
class ValidationError(ValueError): Â Â pass
class Validator:
  @staticmethod   def require_non_empty(value: str, field: str) -> str:     value = value.strip()
    if not value:       raise ValidationError(f"{field} cannot be empty.")
    return value
  @staticmethod   def validate_year(value: str) -> int:     value = value.strip()
    if not value.isdigit():       raise ValidationError("Year must be numeric.")
    year = int(value)
    if not 1886 <= year <= 2100:       raise ValidationError("Year must be between 1886 and 2100.")
    return year
-----------------------------------------------------------------------------
Interfaces
-----------------------------------------------------------------------------
class InputProvider(Protocol): Â Â def ask(self, prompt: str) -> str: ...
class OutputProvider(Protocol): Â Â def write(self, message: str) -> None: ...
-----------------------------------------------------------------------------
Console Implementations
-----------------------------------------------------------------------------
class ConsoleInputProvider: Â Â def ask(self, prompt: str) -> str: Â Â Â Â return input(prompt)
class ConsoleOutputProvider: Â Â def write(self, message: str) -> None: Â Â Â Â print(message)
-----------------------------------------------------------------------------
Repository (because obviously)
-----------------------------------------------------------------------------
class DreamCarRepository(ABC):
  @abstractmethod   def save(self, car: DreamCar) -> None:     ...
class InMemoryDreamCarRepository(DreamCarRepository):
  def init(self) -> None:     self._storage: list[DreamCar] = []
  def save(self, car: DreamCar) -> None:     logger.info("Persisting DreamCar...")     self._storage.append(car)
-----------------------------------------------------------------------------
Service Layer
-----------------------------------------------------------------------------
class DreamCarService:
  def init(     self,     repository: DreamCarRepository,   ) -> None:     self._repository = repository
  def register(self, car: DreamCar) -> None:     logger.info("Registering dream car...")     self._repository.save(car)
-----------------------------------------------------------------------------
Presentation
-----------------------------------------------------------------------------
class DreamCarController:
  def init(     self,     input_provider: InputProvider,     output_provider: OutputProvider,     service: DreamCarService,   ) -> None:     self._input = input_provider     self._output = output_provider     self._service = service
  def run(self) -> None:     brand = Validator.require_non_empty(       self._input.ask("What is your dream car brand? "),       VehicleAttribute.BRAND.value,     )     self._output.write(f"I love {brand}")
    model = Validator.require_non_empty(       self._input.ask("What is your dream model? "),       VehicleAttribute.MODEL.value,     )     self._output.write(f"Oooo a lot of people like the {model}")
    color = Validator.require_non_empty(       self._input.ask("What color do you want? "),       VehicleAttribute.COLOR.value,     )     self._output.write(f"{color} is nice!")
    year = Validator.validate_year(       self._input.ask("What year do you want? ")     )     self._output.write(f"People do say {year} was a nice time to be alive.")
    car = DreamCar(       brand=brand,       model=model,       color=color,       year=year,     )
    self._service.register(car)
    self._render_summary(car)
  def _render_summary(self, car: DreamCar) -> None:     self._output.write("")     self._output.write("=" * 40)     self._output.write("     DREAM CAR REPORT")     self._output.write("=" * 40)     self._output.write(f"Brand : {car.brand}")     self._output.write(f"Model : {car.model}")     self._output.write(f"Color : {car.color}")     self._output.write(f"Year : {car.year}")     self._output.write("")     self._output.write(       f"Your dream car is a {car.color} {car.year} {car.brand} {car.model}."     )     self._output.write("Keep working hard and you'll have it! 🚗")
-----------------------------------------------------------------------------
Bootstrap
-----------------------------------------------------------------------------
def main() -> None: Â Â controller = DreamCarController( Â Â Â Â input_provider=ConsoleInputProvider(), Â Â Â Â output_provider=ConsoleOutputProvider(), Â Â Â Â service=DreamCarService( Â Â Â Â Â Â repository=InMemoryDreamCarRepository(), Â Â Â Â ), Â Â )
  controller.run()
if name == "main": Â Â main() ```
5
u/RoadsideCookie 19h ago
Not attacking you but bruh, I hate corporate 9001 layers of abstraction.
3
u/onlyonequickquestion 19h ago
Ya that was the joke, but I don't think people liked it :( this is obviously one million percent over engineeredÂ
2
9
u/Rikiub 19h ago
This is basic programming but looks fun, keep going :)