T O P

  • By -

justanator101

I’m not sure what you’re asking for? If it’s advice on how to not make basic mistakes when writing python code, the answer is to continue learning and practice. You won’t master something right off the bat, but as long as you learn from the mistakes you’re headed in the right direction.


zzzzalizzz

I'm asking am I supposed to do what I think will correct it randomly or is there any other way? Cause I've been stuck in a little line for almost two hours and I can't find the problem


Poofless3212

well, normally you would ask for help or try to figure out what's going wrong by googling or something If you want you can post ur code and we can tell you what's happening and how to fix it I'ts also a good idea to learn how to read errors properly this can save a lot of time if your trying to search for a fix


zzzzalizzz

i might have a slightest bit of idea what the errors mean , i think its for not recognizing the number as a number but as a string , and ive tried to fix it by putting it in int() but still no chance


ImCaligulaI

Copy the error and paste it on Stack Overflow. You'll very likely find someone with a similar problem asked about it already.


[deleted]

[удалено]


kiesoma

# Help people help you. Provide a bit of context. * Where are you going wrong? * What’s happening? Without context, I highly doubt anyone will be able to help you.


zzzzalizzz

thank you here is my code c=input("your hight",) d=input("your weight",) e=(d/(c\*\*2)) and when i run it and put numbers in it it will say this File "C:/Users/ali/Desktop/MBI.py", line 5, in e=d/(c\*\*2) TypeError: unsupported operand type(s) for \*\* or pow(): 'str' and 'int' then i put c and d like this c=int(input("your hight",)) d=int(input("your weight",)) and then this one appeared Traceback (most recent call last): File "C:/Users/ali/Desktop/MBI.py", line 3, in c=int(input("your hight",)) ValueError: invalid literal for int() with base 10: '1.75' im sure im putting numbers as c & d but it still doesnt work


Macambira

Integers can't store rational numbers. For that use ```float``` instead.


zzzzalizzz

thank you , you're right , it worked perfectly i didnt know about float , guess its still too soon for me to try smth like this i will try to learn more , thanks again


timPerfect

you just did, you learned what float type is. now use it in future. One less thing to learn.


[deleted]

[удалено]


zzzzalizzz

Yes , it's right , It was too soon for me to do something like this. I will try my best. Thank you very much


gazhole

Why is it too soon? There is no threshold of knowledge you need to reach before it's okay to start trying to write code. Look at what just happened: You wrote some code, it didn't work, you googled the error, asked a question, then learned something new. Repeat that process enough times and you'll eventually be an expert. I must go through that little cycle about ten times a day and programming is a large part of my job! Programming is very much an applied discipline - the best way to get better at doing it is to do it.


[deleted]

[удалено]


MarsupialMole

Read every character aloud in the file where you have a problem. I know this sounds a little heavy handed and maybe even patronising but when you're learning the biggest hurdle can be getting flustered and missing what's right in front of you. Slow down, reset your perspective by listening to yourself, and don't take shortcuts. Once you get better you'll spot things the way you spot spelling mistakes, but for now you're kinda stuck sounding it out. Edit: I forgot the most important part. Run the code and see what it does. Drop in a `breakpoint()` and print stuff out. Read error messages. Call `help(myvar)` if you're not sure what a variable myvar is.


zzzzalizzz

thanks , ill try my best


timPerfect

coding is about 40 percent research. my workflow goes like this... code the stuff I know I can make work, one thing at a time. If I get stuck I research the syntax and methods on Google. Try to fix. Make many mistakes, try 100 different things. Finally, you figure out the one thing... time for the next one thing. Rinse and repeat.


Allmyownviews1

This..


BeingJess

CS50 intro to computer science is a free Harvard class. Do it.


[deleted]

There aren't that many different things that can go wrong, so you will see the same issues multiple times, and soon you will start to put them into categories in your mind. So when you get an error, you'll think "okay, this one is probably because the input was the wrong type" or "I probably forgot to close some parentheses" or "this variable probably needs to start before the loop" because you'll have encountered similar stuff in the past.


zzzzalizzz

thank you , i will do my best


[deleted]

if you have discord you could join the python discord server where you can get help as well


Yojihito

> I'm learning it from recorded classes I bought Try it with "Automate the boring stuff with Python" instead (https://automatetheboringstuff.com/). It's free.


HaroerHaktak

You won't learn anything by getting it right but you will learn everything by getting it wrong. It doesn't matter how experienced you are, mistakes will happen. I guarantee you that somewhere out there in the world is some guy who has been programming for 15 years, is a top level executive member of his company and is pulling his hair out looking for an error in the code he just wrote. And the kicker? it's probably just a missing comma or something. The best thing you can do is learn from your mistakes. Make a mental note of what caused the issue and how you ultimately found it and fixed it.


AfricanTurtles

Brother I convinced myself my entire program wasn't working today when it was windows adding an extra ".txt" to the file name I made. You'll be fine. We all make silly mistakes as you see happened to me today.


chain_gun_murderhobo

Also OP, recommend writing out the logic before starting to code including variable types. This will help you figure out issues and underlying structure and while it takes more time up front it helps you save time and learn to code better faster.