I know theres something wrong with the syntax here... print ("this program will check if a number is even") Number1 = input("please enter a number") if Number1 % 2 == 0: print ("the number is even!") else print("the number is odd!") but im not sure what.
I see u have print as a function, what version of Python u have?
ermm 3.3?
-?
U will get problems with MOOC if u use 3 instead of 2 (are you on MOOC?)
yeah I am. Okay i will switch to 2. Is there anything wrong with my if statement?
AFAICS, 2.7.3 seems to work fine.. Let me try your code....
Is Number a class name?
i guess it would be print "this program will check if a number is even" Number1 = raw_input("please enter a number") if Number1 % 2 == 0: print "the number is even!" else print"the number is odd!" for python 2
Number might be, but im using Number1 so i didnt think it would effect it
what about the "else" does it need a : or anything?
I don't know that much about 3, seems that it migh be a problem to start with a capital if that is for Class
U should have else: I am just trying to get it to run....
Okay i have, what is this?
hmmm, seems to work in there
else has to be indented left....
Now I am running as .py file in cmd.exe
so not underneath the print, in the same column as if
After I enter a number it complains about type error please enter a number 5 Traceback (most recent call last): File "F:\!Work\!Coursera\Week1\wolfy.py", line 2, in <module> if Number1 % 2 == 0: TypeError: not all arguments converted during string formatting Let me try it without "Number"
You use raw_input which converts input to string, you should then convert the input to int with int(input) or directly use input() instead of raw_input
I tried aNumber1 and get "not defined"
I suggest this : Number1 = input("please enter a number") if Number1 % 2 == 0: print "the number is even!" else: print"the number is odd!"
@FabienToune Yes....
okay thanks :)
probably be about 2 minutes until im stuck again :)
:-)
The skulptor is what I am using in the Coursera Python course....
why not idle?
It has a stripped down simple GUI
for simple game programming
Everyone is using same thing in the cloud, stops all the problems with version numbers and so on....
oh okay, cool
Their course started exact same time as MOOC so I thought I will try to do both at same time...
But discussion here is better, they have only standard type of forum...
which course?
https://class.coursera.org/interactivepython-2012-001/class/index (maybe u have to register I think)
Back in an hour or so...
i will have a look. With the mooc assignments, we dont actually send them to anyone do we?
There is a timetable of sorts but it really doesn't matter if you fall behind a bit. The other is quite strict (I am not sure I will keep to it in the end)
The indentation level of the else function is not the same of the if function place else outside. It will work. Like this: Number1 = input("please enter a number") if Number1 % 2 == 0: print ("the number is even!") else: print("the number is odd!")
There are two problems here that have already been mentioned separately. First, the 'else' line needs to be at the same indentation level as the 'if' line. Second, the 'else' line should read 'else:' the colon at the end of the line is a very important and forgettable bit of syntax in python. From a purely stylistic standpoint, variable identifiers usually dont begin with a capital letter. Additionally the input begins immediately after the string that you provide for the prompt. something along the lines of 'number1 = input("please enter a number: ")' would be a bit cleaner.
Join our real-time social learning platform and learn together with your friends!