Jump to content

<python> why is this not working?

why is this not working?

inv = (float(input("how much are you investing?:  "))

while inv <= 1000000:
 inv = inv * 0.075 + inv
 print (inv)
 

before doing

 

inv = (float(input("how much are you investing?:  "))

 

 

i wrote

 

inv = 2500

 

^that worked but after i changed it its giving me some error on the while.

 

 

also how can i calculate how many times it looped before stopped?

|:Insert something funny:|

-----------------

*******

#

Link to comment
https://linustechtips.com/topic/1399630-why-is-this-not-working/
Share on other sites

Link to post
Share on other sites

22 minutes ago, adarw said:

^that worked but after i changed it its giving me some error on the while.

It's usually a good idea if you tell us what "some error" is.

 

inv = (float(input("how much are you investing?:  "))

As a hint: Take a close look at the number of opening parentheses and the number closing parentheses. There's your error.

Remember to either quote or @mention others, so they are notified of your reply

Link to post
Share on other sites

14 minutes ago, Eigenvektor said:

It's usually a good idea if you tell us what "some error" is.

 

lol yea.

17 minutes ago, Eigenvektor said:

As a hint: Take a close look at the number of opening parentheses and the number closing parentheses. There's your error.

i am soo dumb, computers are also dumb.

 

28 minutes ago, FalseControl said:
Maybe this might help? 

count = 0

while x != y::
   count +=1 # variable will increment every loop iteration
   # your code


print count

 

Also change your inv = to something else because maybe calc  = inv * 0.075 + inv 

oh thanks.

|:Insert something funny:|

-----------------

*******

#

Link to post
Share on other sites

13 minutes ago, adarw said:

computers are also dumb.

You: *asks me to bring spoon*(says spoon instead of fork)

me: *brings spoon*

You: "I told you to bring the fork, you're so dumb"

 

They do what you say, nothing more, nothing less.

 

 

Here's the error it showed me, and I suppose is what you encountered too:

File "z:\<path>\test.py", line 3
    while inv <= 1000000:
    ^
SyntaxError: invalid syntax

 

It's showing you that error because it expected something in that parenthesis you forgot to close. I get it, it isn't easy to understand at first, but I usually have a habit of checking the line before the one where the error is, as sometimes in Python the error exists on the line before the one that's shown by the compiler. Just make an indentation error and see what it tells. Might help you too.

Spoiler

Like here, the error is clearly on the line after the while statement, and the error is thrown on the next line:

inv = (float(input("how much are you investing?:  ")))

while inv <= 1000000:
    inv+=inv #deliberate indentation error
 print (inv)

 

Error:

print (inv)
               ^
IndentationError: unindent does not match any outer indentation level

See?

 

9 minutes ago, adarw said:

like what does the = mean? does this just mean count = count +1?

Just means count = count + 1, is a shorthand form of writing that.

Edited by RockSolid1106
On 4/5/2024 at 10:13 PM, LAwLz said:

I am getting pretty fucking sick and tired of the "watch something else" responses. It's such a cop out answer because you could say that about basically anything, and it doesn't address the actual complaints. People use it as some kind of card they pull when they can't actually respond to the criticism raised but they still feel like they need to defend some company/person. If you don't like this thread then stop reading it. See how stupid it is? It's basically like telling someone "shut the fuck up". It's not a clever responsive, it doesn't address anything said, and it is rude. 

 ^

-----

MKBHD is but an Apple propagandist and fanboy. Take his videos with a grain of salt, especially about anything Apple. In his video titled "I Visited Apple's Secret iPhone Testing Labs!", he has shown that he makes no effort to fact check Apple's claims, and takes it at face value. I do not believe he can be trusted as an Reviewer/Influencer.

-----

bruh switch to dark mode its at the bottom of this page

VPN Server Guide

Link to post
Share on other sites

1 hour ago, RockSolid1106 said:
1 hour ago, adarw said:

 

You: *asks me to bring spoon*(says spoon instead of fork)

me: *brings spoon*

You: "I told you to bring the fork, you're so dumb"

 

They do what you say, nothing more, nothing less.

 

yea ik, but the fact that missing a bracket makes your command (code) go berserk is stupid. but i mean its quite cool

|:Insert something funny:|

-----------------

*******

#

Link to post
Share on other sites

2 hours ago, adarw said:

i am soo dumb.

 

No worries, this sort of simple mistake happens to me almost daily.

Be careful with those parentheses - are you using an IDE? Many will close your brackets for you when you put one in and let the IDE auto complete the functions such as "float()" and "input()".

Link to post
Share on other sites

1 minute ago, delph said:

 

No worries, this sort of simple mistake happens to me almost daily.

Be careful with those parentheses - are you using an IDE? Many will close your brackets for you when you put one in and let the IDE auto complete the functions such as "float()" and "input()".

im using replit.com right now, i like the interface but im not sure if theres a way i can make it close the parentheses, it does close the ""

|:Insert something funny:|

-----------------

*******

#

Link to post
Share on other sites

2 hours ago, adarw said:

but the fact that missing a bracket makes your command (code) go berserk is stupid.

Well the other only alternative is it tries to guess and instead of an error that doesn't let you run your code it'll run but do something completely wrong most of the time and the problem will be way harder to find...

F@H
Desktop: i9-13900K, ASUS Z790-E, 64GB DDR5-6000 CL36, RTX3080, 2TB MP600 Pro XT, 2TB SX8200Pro, 2x16TB Ironwolf RAID0, Corsair HX1200, Antec Vortex 360 AIO, Thermaltake Versa H25 TG, Samsung 4K curved 49" TV, 23" secondary, Mountain Everest Max

Mobile SFF rig: i9-9900K, Noctua NH-L9i, Asrock Z390 Phantom ITX-AC, 32GB, GTX1070, 2x1TB SX8200Pro RAID0, 2x5TB 2.5" HDD RAID0, Athena 500W Flex (Noctua fan), Custom 4.7l 3D printed case

 

Asus Zenbook UM325UA, Ryzen 7 5700u, 16GB, 1TB, OLED

 

GPD Win 2

Link to post
Share on other sites

10 hours ago, adarw said:

yea ik, but the fact that missing a bracket makes your command (code) go berserk is stupid.

Ok, can you tell me the solution of

(1 + 2) * 3

?

 

What about

(1 + 2 * 3

?

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to post
Share on other sites

11 hours ago, adarw said:

yea ik, but the fact that missing a bracket makes your command (code) go berserk is stupid. but i mean its quite cool

It doesn't go berserk, it simply tells you there's an error with your syntax. The reason it complains about the "while" is that this is the first unexpected item the compiler encounters while searching for the closing parenthesis. It needs the closing parenthesis to figure out where your statement ends, just as @Sauron's example illustrates.

 

inv = float(input("how much are you investing?:  ") // <-- missing closing ), so compiler keeps looking

while inv <= 1000000:
^-- compiler encounters an item that definitely can't be inside the ), so it complains here

 

That's the downside of a language that has a relaxed syntax, the compiler has to do much more guesswork. Languages with a stricter syntax can often provide better error message.

Remember to either quote or @mention others, so they are notified of your reply

Link to post
Share on other sites

11 minutes ago, Eigenvektor said:

That's the downside of a language that has a relaxed syntax, the compiler has to do much more guesswork. Languages with a stricter syntax can often provide better error message.

Missing bracket errors are often pretty confusing even in languages like C, precisely because the compiler can't really guess where the bracket was supposed to be.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to post
Share on other sites

4 hours ago, Sauron said:

Ok, can you tell me the solution of

(1 + 2) * 3

?

 

What about

(1 + 2 * 3

?

lol your right. XD

3 hours ago, Sauron said:

Missing bracket errors are often pretty confusing even in languages like C, precisely because the compiler can't really guess where the bracket was supposed to be.

i found c to be easier to trouble shoot, but its not perfect.

|:Insert something funny:|

-----------------

*******

#

Link to post
Share on other sites

19 hours ago, adarw said:

i found c to be easier to trouble shoot, but its not perfect.

Do you even malloc?

 

pro-tip: use malloc statically. Dynamic malloc inflicts a lot of pain.

 

Also it depends on your debugger/compiler.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×