Jump to content
xisto Community
arcanistherogue

Need Help With My Python Programs just extremely basic stuff

Recommended Posts

ok, i am learning python, and i realy dont know much. my guide im using said to make a program where it asks your name, and if the name is yours your make it so there is a compliment, if it is another name you make it that its an insult, and anything else makes it say Nice name.here is what i wrotename = raw_input("What is your name?")if name == John: print "Your name is freaking sweet, you must be a god or something."elif name == Bob: print "You have a freakin' weird name, dude."else: print "Nice name,",namei donot understand what i am doing wrong, i get this error when i run it:What is your name? JohnTraceback (most recent call last): File "C:/Python23/name.py", line 4, in -toplevel- if name == John :NameError: name 'John' is not definedcan someone help me please?thanks for any response.

Share this post


Link to post
Share on other sites

CHOMP CHOMP CHOMP.Very understandable error. Just like forgetting ';' in languages that need it (PHP, Java and so on). I'm just glad you hadn't got to somewhere where you had made hundreds of lines of code (and posted here) :DI'm glad I could help and good luck with the further learning :D

Share this post


Link to post
Share on other sites

thanks alot. right now im working on a math helper program, that has a list of many formulas. It will start out as a list of basic things, like area, etc, then when you select one it goes more in depth, like area of a quadrilateral, then maybe like area of a square or whatnot. what i want to have it do is to have a loop back to the main page after each formula, and i put if selection == 0 it displays the main screen, and all of the formulas have a number near them so you input the corressponding number to select the certain formula. what i want to know is, this is a basic idea of what i have, i want to know if it will work:selection = 0if selection ==0: print "choose a formula" print "1. area" selection = raw_input if selection == 1: print "a. area of a square" selection = raw_input if selection == a a = raw_input("Length of a side?") b = a*a print b selection = 0will that work? like will it loop back at the end of the formula?and also, can i have multiple If's, or do i just put in multiple elif's?

Share this post


Link to post
Share on other sites

and also, can i have multiple If's, or do i just put in multiple elif's?

I have to admit that I know very little about Python, so I don't really know how it would work if you wanted it to jump back to the beginning sometimes.

What I can tell you is that you shouldn't use elif's for the bit that you've written so far, once you have some more options on each level you can do that. But those if's you have at the moment should stay if's, because they are conditions that shouldn't be checked before the if before them has been checked.

Share this post


Link to post
Share on other sites

I agree with what the above poster said. I find case neater but some books suggest avoiding it. I don?t know if python has a case. If not use else if although you could just as well use if. It is just less efficient and perhaps less readable. Also if you mathhelpers become long it is better to make them functions. On a side note I thought python was a functional programming language. From the code you showed me it looks like an imperative language like c.

Share this post


Link to post
Share on other sites

python

Need Help With My Python Programs

 

Hi,

 

I am very new to python.I need to write a program for a cluster.

Imagine a situation where there are three machines A,B,C clustered in a domain.If one machine goes down the other two should get notified by a message/email.Is it possible to write a script for that??Please help

 

-question by Kalpana

Share this post


Link to post
Share on other sites

basic program

Need Help With My Python Programs

 

Hello, I need help! I worte this

 

Name = raw_input("What is your name?")

If name == "Mario":

Print 'Hello, thats a beautiful name!'

Else:

Print "Hi, nice name,",name

 

I do not know whats wrong and it keeps on giving me errors,

 

Treaceback <most recent call last>:

File "<stdin>", line1, in <module>

Import Error: No module named name

 

I will appreciate any help!

Thank you

Marsal

 

-question by Mario

Share this post


Link to post
Share on other sites
Replying to Trap FeedBackerName = raw_input("What is your name?")If name == "Mario":You made a variable Name, but rewrote it as name. Its just a problem with the uppercase/lowercase and...Sooo:Name = raw_input("What is your name?")If name == "Mario":-reply by George

Share this post


Link to post
Share on other sites

Case of letters

Need Help With My Python Programs

 

Replying to Trap FeedBacker

The problem with your program is most like the upper case in the original variable "Name". After the first line you type name with a lowercase. Python is very very case sensitive. So if you just replace the first Name with a lowercase name it should work. So it will look like this.

 

Name = raw_input("What is your name?")

If name == "Mario":

Print 'Hello, thats a beautiful name!'

Else:

Print "Hi, nice name,",name

 

-reply by Zemeus

Share this post


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

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.