Almost no codes are working for me in Command Line

This is the place for queries that don't fit in any of the other categories.

Almost no codes are working for me in Command Line

Postby crazzyjoel » Wed Aug 14, 2013 4:34 pm

Hello everyone,

Im totally new to this and everything which involves programming. You can call me a noob, weirdo or tell me that i should've never even started with programming from the first sight, if i don't know how to do this. But i really want to learn how to program, OK, here we go :)

Whenever i try to execute some sort of code using Command Line i get like perhaps... 90 % of the cases some sort of an error-message. I get really frustrated about this and i can't figure it out, how to solve my problem. I'm really doing what i was told to do through my programming-course website. Yes, i'm reading a course, though it's a distance course so i can't really talk with my teachers more than chatting with them through a forum. I don't think they are very helpful anyway.

Here are some codes i've been having problems with:

Code: Select all
print("Charles is", end=" ")
Charles is >>> age = 2006-1987
print(age, "years old")


This was my first (i never got any error-message when i executed this though) issue in the programming course. According to my teachers, when i execute this, "Charlie is 19 years old" should be on the same line. But when i execute it, it looks like this

Code: Select all
print("Charles is", end=" ")
Charles is >>> age = 2006-1987
print(age, "years old")

Charles is
19 years old


My teachers wants me to use a program called IDLE, but i have tried it and it doesn't work for me. I saved the file as "zzz.py" and tried to press F5 to execute the file (I have also tried to find any menu or something which says "run" or "execute"). But with no luck. I have also read that IDLE isn't any good program for some reason. Anyway the command Line isn't maybe the right program to start with as a newbie as me? Do you know any better program or am I using the command Line wrong, perhaps? When I use Command Line the only thing i do is entering the program and start "coding".

Also just to show you 1 more example, i will show you this:

Code: Select all
temperature = int(input("Give temperature: "))
if temperature < 5:
print("Burr, It's cold today!")


But unfortunately an error-message occurred.

Code: Select all
>>> temperature = int(input("Give temperature: "))
Give temperature: 4
>>> if temperature < 5:
... print("Burr, it's cold today!")

File "<stdin>", line 2
print("Burr, it's cold today!")

IndentationError: expected an intented block

The meaning with this code is to input a number and let the program (computer) decide if 5 is more or less than the number i was inputting. If it's true that 5 is higher then 4 then my program should also execute "Burr, it's cold today!", but it won't do it! :(

This is 2 examples from my course. I can even finish this course without even touching python but i'm not doing this just to get a grade in this course. I'm doing this summer-course because i want to learn programming. So if any kind people could help me out, I would be more than happy. Cheers! :)

regards Joel
crazzyjoel
 
Posts: 4
Joined: Tue Aug 13, 2013 10:03 am

Re: Almost no codes are working for me in Command Line

Postby metulburr » Wed Aug 14, 2013 4:58 pm

I beleive you are confused and mixing up the use and syntax with the interpreter, command line, and just using a file.

There is more than one way to run python code. You can use IDLE which is one IDE, there are many more. This does all the stuff for you. Which running in IDLE i think there should be an option somewhere, to "run module" which is essentially execute. OR, instead of IDLE, you can use the command line to just run a file. This method you just put the code in a file and run it via command line. The interpreter however is something completely different. This is indicated by ">>>" which is the python interpreter prompt. This is the output from the interpreter:
Code: Select all
Charles is >>>


the actual code is:
Code: Select all
print("Charles is", end=" ")
age = 2006-1987
print(age, "years old")


if you put the output of the interpreter in the file, it is just going to end up with a syntax error, as it is not valid syntax for code, just hte output of the interpreter.

This tutorial tries to explain the difference in detail of these:
viewtopic.php?f=25&t=55
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1416
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY


Return to General Coding Help

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot], crazychemist, mastermind1, micseydel and 3 guests