Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 7 Online
OpenStudy (anonymous):

I am trying to run the below program using python 3.3 but it is giving me syntax error: x = int(input('Enter and Integer:') if x % 2 == 0: print('Even') else: print('Odd') if x%3 != 0: print('And not divisible by 3')

OpenStudy (anonymous):

you need to indent after if and else statements.

OpenStudy (anonymous):

you don't need to indent after an assignment statement.

OpenStudy (anonymous):

``` x = int(input('Enter and Integer:') if x % 2 == 0: print('Even') else: print('Odd') if x % 3 != 0: print('And not divisible by 3') ```

OpenStudy (anonymous):

Oh, also you missed a parenthesis: ``` x = int(input('Enter and Integer:')) if x % 2 == 0: print('Even') else: print('Odd') if x % 3 != 0: print('And not divisible by 3') ```

OpenStudy (anonymous):

it is working now, thank. however if someone can explain to me indentation.. little bit confused

OpenStudy (anonymous):

You will always indent after lines that end in a `:`

OpenStudy (anonymous):

You put `:` after `if`, `else`, `elif`, `while`, `for`, `def`, and `class` statements. There maybe more I am missing, but basically when you are defining something (like a function or class), if you are doing some sort of `if` / `else` thing, or if you are doing a loop, then you need `:` and follow it up by an indent.

OpenStudy (anonymous):

i got u.. thanks

OpenStudy (rbx):

If there is a single statement in an if block, you can write it in same line like if x > 3: print("Yes") but if you need to start a new block to include multiple statements, you have to place a newline and indent the block like if x > 3: statement 1 in if block statement 2 in if block a statement outside if block

OpenStudy (anonymous):

hi guys, i went through the recitation 1, i feel that it was too long programs for a beginner to understand. i could just run the cube root of perfect cube and the range program without clear understanding how the program run. what i am asking as help , is for someone to split the two examples into small ones and explain to me step-by-step. then give me some basic exercises related to them to try them... i do not understand... but i am not giving up... this is where my story as expert programmer should begin.. thanks you guys

OpenStudy (rbx):

I have been through just 4 lectures and I can't find any recitation among what I have. Try creating a new question someone might answer it. Also if it is in one of the lectures, please tell me the lecture number (I have fall 2008 lectures).

OpenStudy (rbx):

I don't have a internet connection good enough to view the recitation right now, but in what lectures I have a flow chart approach was depicted in one of them. You should try making your own flow charts while trying to figure out how you would solve the problem. |dw:1393873973031:dw| This is what I could make, assuming what the solution might have been. Here you first check if the number is positive. Then you again and again (brute force) create cubes to check if they are less than the required cube, and then increment the number (ans). After you are done (the loop exits), you check if your generated cube is exactly equal to the cube whose root is required, if not then the cube wasn't perfect. If you need help with code and syntax, give me the program you wrote, I'll try dissecting it/ correcting it.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!